Happy Coder
Happy Coder

Reputation: 4692

Elasticsearch which is the better aggregation

I need to run a an aggregation which is to get the unique ids for a day where the ids in the specific set. So the SQL query will be like

SELECT count (DISTICT my_field) FROM my_table WHERE time BETWEEN '2015-02-13 00:00:00' AND '2015-02-13 23:59:59' AND my_field IN (value1,value2,value3....value n)

I am now using terms aggregation, and counting the number of buckets. But it is resulting in wrong counts and I am getting the bucket count as the number of values for "my_field" I specified in the query string. So is there any better method for doing this ?

By the way, I have over 4k values which need to be checked against for a day. I mean in the where condition.

Upvotes: 0

Views: 63

Answers (1)

bittusarkar
bittusarkar

Reputation: 6357

You can use Cardinality Aggregation along with Filter Aggregation to get what you need. In the filter section of filter aggregation, encode your where clause and add the cardinality aggregation to get the count of distinct values of my_field field.

Upvotes: 1

Related Questions