Elasticsearch nested aggregate query with filter

I'm trying to apply a filter to a nested aggregate query. I'm unable to apply the filter.

I have data like below. Nested dictionaries(each represent an address) in a list. Some of the addresses have "geo_location" and some of them do not. I want to find out the counts of "type" of addresses(aggregate query). for ex: type 1: 45000, type 2: 40,000, but I want the count only for the addresses which do not have "geo_location" field populated.

"addresses": [
            {
              "geo_location": {
                "lat": 42.407345,
                "lon": -83.169199
              },

              "type": 1,
              "addr_id": 26816125,

            },
            {

              "geo_source": "RESIDENTIAL",
              "geo_location": {
                "lat": 42.352785,
                "lon": -83.311244
              },
              "type": 1,

            },
              {
              "type": 2,
              "addr_id": 3374602,
            },
            {
              "type": 2,
              "addr_id": 99446474,
            }
          ]

I have tried to do an aggregate based on the types, but I'm unable to filter it for the addresses which do not have "geo_location" field in it.

GET /search/_search
{
  "size": 0,
  "aggs": {
    "Nesting": {
      "nested": {
        "path": "addresses"
      },

      "aggs": {
        "keyword_names": {
          "terms": {
            "field": "addresses.type",
            "size": 100
          }    }
      }
    }
  }
}

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