Returning only aggregation results

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:

  1. GET /my-index-000001/_search
  2. {
  3. "size": 0,
  4. "aggregations": {
  5. "my_agg": {
  6. "terms": {
  7. "field": "user.id"
  8. }
  9. }
  10. }
  11. }

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