Yeah, you are right, and the low values of the prices in my example did not help me to understand that aggregation.
I don't think there's a way to do this in Elasticsearch in a single query, but I may be wrong, so I will share here at least the data preparation as per your details, and I'll transfer this to the Elasticsearch forum.
If there's a way to run this in ES, then maybe you can configure a Vega visualization that runs that custom query to render your data.
Sorry for not being of much help here
# Create the index
PUT discuss-344485
{
"mappings": {
"properties": {
"ts": {"type": "date"},
"metric": {"type": "integer" }
}
}
}
# Add data for two days with different values
POST discuss-344485/_bulk
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 200 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 200 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 500 }
{ "index": {}}
{ "ts": "2023-10-10", "metric": 500 }
{ "index": {}}
{ "ts": "2023-10-11", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-11", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-11", "metric": 50 }
{ "index": {}}
{ "ts": "2023-10-11", "metric": 100 }
{ "index": {}}
{ "ts": "2023-10-11", "metric": 500 }
With a percentiles aggregation, you only have the values but not the counts. i don't see how to take those values in a subsequent aggregation to retrieve that data.
# Get the 50/80/90 percentiles
GET discuss-344485/_search
{
"size": 0,
"aggs": {
"by_date": {
"date_histogram": {
"field": "ts",
"calendar_interval": "day"
},
"aggs": {
"by_percentile": {
"percentiles": {
"field": "metric",
"percents": [ 50, 80, 90 ]
}
}
}
}
}
}
# Returns
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 25,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"by_date": {
"buckets": [
{
"key_as_string": "2023-10-10T00:00:00.000Z",
"key": 1696896000000,
"doc_count": 20,
"by_percentile": {
"values": {
"50.0": 50,
"80.0": 120.00000000000011,
"90.0": 230.00000000000043
}
}
},
{
"key_as_string": "2023-10-11T00:00:00.000Z",
"key": 1696982400000,
"doc_count": 5,
"by_percentile": {
"values": {
"50.0": 50,
"80.0": 180.00000000000006,
"90.0": 340
}
}
}
]
}
}
}