Muninn.Aggregation (Muninn v0.5.5)

View Source

Builder for constructing aggregation requests.

Aggregations compute analytics over search results — counting documents per category, computing average prices, building histograms, etc.

Examples

alias Muninn.Aggregation
alias Muninn.Aggregation.{Bucket, Metric}

# Simple terms aggregation
aggs = Aggregation.new()
  |> Aggregation.add("categories", Bucket.terms("category", size: 10))

{:ok, results} = Muninn.Searcher.aggregate(searcher, "*", ["title"], aggs)

# Nested: stats per category
aggs = Aggregation.new()
  |> Aggregation.add("categories",
    Bucket.terms("category", size: 10)
    |> Aggregation.sub("price_stats", Metric.stats("price"))
  )

Summary

Functions

Adds a named aggregation to the request.

Creates a new empty aggregation request.

Adds a sub-aggregation to a bucket aggregation.

Types

t()

@type t() :: map()

Functions

add(aggs, name, aggregation)

@spec add(t(), String.t(), map()) :: t()

Adds a named aggregation to the request.

new()

@spec new() :: t()

Creates a new empty aggregation request.

sub(parent_agg, name, child_agg)

@spec sub(map(), String.t(), map()) :: map()

Adds a sub-aggregation to a bucket aggregation.