I have a documents with fields campaign_id
(not unique), clicks
(same for each campaign_id
).
How to count sum of unique campaign_id
s clicks
. e.g.
campaign_id=1, clicks=2;
campaign_id=2, clicks=3;
campaign_id=1, clicks=2;
Sum of unique campaign_id
's clicks
will be 5.
Main idea is to get documents with unique campaign_ids
and then sum.
How to create such query in Elasticsearch?
Tried to achieve this using filters inside aggregation but filter should be a bucket instead of metrics.