We can find the Average of fields of all of the docs by using simple Metric. Great!
We can find the Average of Averages per day using Average Bucket. Great!
But how do we find Average of fields in single unique document by a field for a day?
For example, assume we have these documents with fields code, price and date:
{ code: BTC, price: 30000, date: 23/02/2022 },
{ code: BTC, price: 30000, date: 23/02/2022 },
{ code: ETH, price: 5000, date: 23/02/2022 },
{ code: BTC, price: 50000, date: 24/02/2022 },
{ code: BTC, price: 50000, date: 24/02/2022 },
{ code: BTC, price: 50000, date: 24/02/2022 },
{ code: ETH, price: 7000, date: 24/02/2022 }
Now, my issue is that I have duplicate entries for code for each day. When I am finding averages, I want to count a code only once for each day.
So the idea is to calculate averages of price for unique codes per day.
I cannot figure this out using Bucket Pipelines. I need a bucket with unique (average, min or max) values for each day and then calculate its averages.
So, in the example above, for code: BTC, I do not need:
average = (30000 + 30000 + 30000 + 50000 + 50000)/5 = 38000
But I need the average to be:
average = (30000 + 50000)/2 = 40000