Muninn.Aggregation.Bucket (Muninn v0.5.5)

View Source

Bucket aggregation builders.

Bucket aggregations group documents into buckets based on field values, ranges, or other criteria.

Summary

Functions

Filters documents for sub-aggregations.

Groups documents into fixed-width numeric buckets.

Groups documents by numeric ranges.

Groups documents by field values.

Functions

filter(filter_query)

@spec filter(map()) :: map()

Filters documents for sub-aggregations.

Examples

Bucket.filter(%{"term" => %{"status" => "active"}})

histogram(field, interval, opts \\ [])

@spec histogram(String.t(), number(), keyword()) :: map()

Groups documents into fixed-width numeric buckets.

Options

  • :offset - Bucket boundary offset
  • :min_doc_count - Minimum document count

Examples

Bucket.histogram("price", 10.0)

range(field, ranges)

@spec range(String.t(), [map()]) :: map()

Groups documents by numeric ranges.

Examples

Bucket.range("price", [
  %{"to" => 50.0},
  %{"from" => 50.0, "to" => 100.0},
  %{"from" => 100.0}
])

terms(field, opts \\ [])

@spec terms(
  String.t(),
  keyword()
) :: map()

Groups documents by field values.

Options

  • :size - Maximum number of buckets to return
  • :min_doc_count - Minimum document count for a bucket to be included
  • :order - Sort order for buckets (e.g., %{"_count" => "asc"})

Examples

Bucket.terms("category", size: 10)