How do I get unique ids from a geoquery?


(saipa) #1

I have millions of documents, each represents a point in time of individually tracked insects and their heart rate, speed, location, etc.

Is there a way to efficiently query based off of a specific bounding box of latitude longitude, and a time range, and return all the "UNIQUE/DISTINCT" values for a specific field? (i.e. insect_id)? If so, how?

I can see a query returning well over 20,000 documents, of which there may only be 10 unique/distinct insect_id. Whats the most efficient way to do this?


(Mike Simos) #2

If you want unique values you can use a terms aggregation:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

Or you can use a cardinality aggregation:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html


(system) #3