stats aggregations
I can't seem to get stats aggregations to work. I get back something like
"unit_price_stats" => %Snap.Aggregation{
buckets: nil,
doc_count: nil,
doc_count_error_upper_bound: nil,
interval: nil,
sum_other_doc_count: nil,
value: nil
}
I think the problem is that elasticsearch doesn't return buckets etc. for stats aggregations - it returns something like
"aggregations": {
"grades_stats": {
"count": 2,
"min": 50.0,
"max": 100.0,
"avg": 75.0,
"sum": 150.0
}
}
Thanks - can you share the query you're using?
Hi @tomtaylor this is the documentation for the stats aggregation: https://www.elastic.co/guide/en/elasticsearch/reference/8.11/search-aggregations-metrics-stats-aggregation.html I was surprised that this doesn't follow the standard aggregation. It seems to be a special aggregation.
Maybe an additional struct StatsAggregation? And then one can match on the values of the map to determine whether to return a Snap.Aggregation or a Snap.StatsAggregation?
Something along the lines of:
def build_aggregations(aggregations) when is_map(aggregations) do
Map.new(aggregations, fn
{key, %{"count" => _, "min" => _, "max" => _, "avg" => _, "sum" => _} = value} -> {key, Snap.StatsAggregation.new(value)}
{key, value} -> {key, Snap.Aggregation.new(value)}
end)
end
yeah something as simple as that would be awesome, but at a high level elasticsearch/opensearch support 2 types of aggregations, one is called a bucket aggregation which seems to be supported and the other type is a metrics aggregation which isn't.
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
even if we had a generic aggregation where it just returned the ES data as json it would at least mean that there was some way to get it with Snap