How to return the count of unique documents by using elasticsearch aggregation


Is there a way to return the count of the unique documents by using

My use case is pretty simple:

In my data model I have an array of locations :
"locations" : [
"city" : "new york",
"state" : "ny"
"city" : "woodbury",
"state" : "ny"

The "locations" field is of nested object, and it has "city" and "state"

Let's say I only have this one entry in my elasticsearch server and I ran
terms aggregation on the state field, however the doc_count in the "ny"
bucket is 2 rather than 1.

Basically I want elasticsearch to return the count of distinct results (or
return the distinct results).

Is there anyway to do it?


You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit