mkc
mkc

Reputation: 104

Elasticsearch Ignoring Filter in Aggregations

The request looks something like:

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

The response looks something like:

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

The "doc_count" in the aggregation is what the results would be without the "filter" and just the "query". The "filter" seems to be ignored.

This was working at some point, but all of a sudden doesn't seem to be working. Anyone have any clue?

Elasticsearch 1.5.2, NEST 1.4.3.

Thanks.

Upvotes: 3

Views: 2070

Answers (1)

James Addison
James Addison

Reputation: 3094

filter used at the top level of your DSL query has been renamed to post_filter (see https://github.com/elastic/elasticsearch/issues/4119). Documentation for post_filter is here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html

I'm not sure whether it applies or not to your particular query, but you might want to use the filtered query type: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

Upvotes: 5

Related Questions