Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats aggregations #33

Open
nickkaltner opened this issue Oct 23, 2022 · 4 comments · May be fixed by #92
Open

stats aggregations #33

nickkaltner opened this issue Oct 23, 2022 · 4 comments · May be fixed by #92

Comments

@nickkaltner
Copy link

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
    }
  }
@tomtaylor
Copy link
Collaborator

Thanks - can you share the query you're using?

@Ivor
Copy link

Ivor commented Nov 28, 2023

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

@nickkaltner
Copy link
Author

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

@nickkaltner
Copy link
Author

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

@nickkaltner nickkaltner linked a pull request Mar 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants