Filter aggregation

Filter aggregation #

A single-bucket aggregation that narrows the documents a nested aggregation runs on, with a query acting as the filter condition.

Examples #

Average price of t-shirt sales only:

POST /sales/_search
{
  "aggs": {
    "t_shirts": {
      "filter": { "term": { "field": "type", "value": "t-shirt" } },
      "aggs": {
        "avg_price": { "avg": { "field": "price" } }
      }
    }
  }
}

Parameters for filter #

  • <filter query>
    (Required, query) The filter condition — any single query clause in the map form, e.g. {"term": {...}}.
  • aggs
    (Required, object) Nested sub-aggregations, computed over only the matching documents.

For multiple named filters in one aggregation, see filters.

Calendar September 26, 2026
Edit Edit this page