本文介绍了ES:具有直方图facet的直方图facet,all_terms = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎不支持all_terms = true(即:即使count = 0,返回facetvalue / bucket)

Elasticsearch Histogramfacet doesn't appear to support all_terms = true (i.e: return facetvalue / bucket even though count=0)

这是否正确?

推荐答案

是的,这是正确的。但是,如果您没有使用相关性对结果进行排序,则可以将查询移动到顶层过滤器元素中,并将 match_all 进入顶层查询元素。例如,对于以下请求将返回两个直方图 - 一个仅与对应于查询的元素,另一个用于整个索引:

Yes, this is correct. However, if you are not using relevancy to sort your results you can move your query into the top-level filter element and put match_all into the top-level query element. For example, for following request will return two histograms - one only with elements that correspond to the query and another one for entire index:

{
    "query": {
        "match_all": {}
    },
    "filter": {
        // filter goes here
    },
    "facets": {
        "histo_all": {
            "histogram": {
                "field": "my_field"
            }
        },
        "histo": {
            "histogram": {
                "field": "my_field"
            },
            "facet_filter": {
                // same filter from top-level filter goes here
            }
        }
    }
}

这篇关于ES:具有直方图facet的直方图facet,all_terms = true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:01