【问题标题】:Elasticsearch Ignoring Filter in AggregationsElasticsearch 忽略聚合中的过滤器
【发布时间】:2015-07-18 07:40:27
【问题描述】:

请求看起来像:

{
    "aggs": {
        "contentType": {
            "terms": {
                "field": "contentType",
                "size": 0
            }
        }
    },
    "query": {...},
    "filter": {...}
}

响应类似于:

{
    "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
                }
            ]
        }
    }
}

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

这在某些时候起作用,但突然之间似乎不起作用。有人知道吗?

Elasticsearch 1.5.2、NEST 1.4.3。

谢谢。

【问题讨论】:

标签: elasticsearch filter nest


【解决方案1】:

在 DSL 查询的顶层使用的filter 已重命名为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

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多