New

The executive guide to generative AI

Read more

Returning only aggregation results

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Returning only aggregation results

edit

There are many occasions when aggregations are required but search hits are not. For these cases the hits can be ignored by setting size=0. For example:

$ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
  "size": 0,
  "aggregations": {
    "my_agg": {
      "terms": {
        "field": "text"
      }
    }
  }
}
'

Setting size to 0 avoids executing the fetch phase of the search making the request more efficient.

Was this helpful?
Feedback