Count unique values from the filter query result, taking two fields into account

I have a query that filters the "desc = mls or door = 33". Next I want a count value with a agregations the unique values in two fields.

 "query": {
    "nested": {
      "path": "data.addresses",
      "inner_hits": {
        "_source": ["data.addresses.p"],
        "size":100
      },
      "query": {
        "nested": {
          "path": "data.addresses.services",
          "inner_hits": {
        "_source": ["data.addresses.p", "data.addresses.services.door",
        "size":100
      }, 
      "query": {
        "bool": {
          "should": [
              {"match": {"data.addresses.services.desc": "mls"}},
              {"term": { "data.addresses.services.door.keyword": "33"}}
              ]
            }
          }
        }
      }
    }
  },
  "aggs": {
    "nestedP": {
      "nested": {
        "path": "data.addresses"
      },
      "aggs": {
        "termField": {
          "terms": {
            "field": "data.addresses.p.keyword",
            "size": 1000
          },
          "aggs": {
            "NESTEdoor": {
              "nested": {
                "path": "data.addresses.services"
              },
              "aggs": {
                "AGGPOR": {
                  "terms": {
                    "field": "data.addresses.services.door.keyword",
                    "size": 1000
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

I have a query that filters the "desc = mls or door = 33". Next I want a count value with a agregations the unique values in two fields.

output of fitler query:

  {
    "data.addresses.services.desc.keyword" : "mls",<---- same mls and 33
    "data.addresses.services.door.keyword" : 33
  },
  {
    "data.addresses.services.desc.keyword" : "mls",<---- same mls and 33
    "data.addresses.services.door.keyword" : 33
  },
  {
    "data.addresses.services.desc.keyword" : "mls",<---- diferent port 33
    "data.addresses.services.door.keyword" : 98

  },

I am trying to make agregations about the output of the filter query for to get a count value :
Desired output aggregation

 {
    "key" : "mls",
    "doc_count" : 2
  },

Is possible to get a query that counts how many unique values ​​the result of the query filter has taking into account two fields?

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