Elasticsearch 忽略聚合中的过滤器

mkc*_*mkc 3 filter elasticsearch nest

该请求看起来像:

{
    "aggs": {
        "contentType": {
            "terms": {
                "field": "contentType",
                "size": 0
            }
        }
    },
    "query": {...},
    "filter": {...}
}
Run Code Online (Sandbox Code Playgroud)

响应看起来像这样:

{
    "took": 300,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "hits": {
        "total": 68,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "contentType": {
            "doct_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": 9
                    "doc_count": 7054
                },
                {
                    "key": 9
                    "doc_count": 7054
                },
                {
                    "key": 5
                    "doc_count": 6236
                },
                {
                    "key": 4
                    "doc_count": 1124
                }
            ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

聚合中的“doc_count”是没有“过滤器”而只有“查询”的结果。“过滤器”似乎被忽略了。

这在某些时候是有效的,但突然间似乎不起作用了。有人有任何线索吗?

Elasticsearch 1.5.2、NEST 1.4.3。

谢谢。

Jam*_*son 5

filterDSL 查询顶层使用的内容已重命名为post_filter(请参阅https://github.com/elastic/elasticsearch/issues/4119)。文档post_filter位于: https: //www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html

我不确定它是否适用于您的特定查询,但您可能想使用filtered查询类型:https ://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered -query.html