Elasticsearch 5 | filter nested object and nested aggregation count

elasticsearch 5.2

I want to filter my items by the nested object state.id = 101 and an aggregation count for all the items by state.id. There are items with the state ids 101, 102 and 103.

The aggregation count is now limited to state.id 101. I want only get the items with state.id = 101 and the aggregation count for all state ids.

How can i do that?

GET index/items/_search
{
  "query": {
        "nested" : {
            "path" : "state",
            "query": {
              "bool": {
                "filter": {
                  "term": { "state.id": 101 }
                }
              }
            }
        }
  },
     "aggs" : {
        "state" : {
            "nested" : {
                "path" : "state"
            },
            "aggs" : {
                "count" : { "terms" : { "field" : "state.id" } }
            }
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.