This version of the OpenSearch documentation is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Filter aggregations

A filter aggregation is a query clause, exactly like a search query — match or term or range. You can use the filter aggregation to narrow down the entire set of documents to a specific set before creating buckets.

The following example shows the avg aggregation running within the context of a filter. The avg aggregation only aggregates the documents that match the range query:

  1. GET opensearch_dashboards_sample_data_ecommerce/_search
  2. {
  3. "size": 0,
  4. "aggs": {
  5. "low_value": {
  6. "filter": {
  7. "range": {
  8. "taxful_total_price": {
  9. "lte": 50
  10. }
  11. }
  12. },
  13. "aggs": {
  14. "avg_amount": {
  15. "avg": {
  16. "field": "taxful_total_price"
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }

copy

Example response

  1. ...
  2. "aggregations" : {
  3. "low_value" : {
  4. "doc_count" : 1633,
  5. "avg_amount" : {
  6. "value" : 38.363175998928355
  7. }
  8. }
  9. }
  10. }