We typically write search queries with three goals in mind:
- retrieval of a (paginated) subset of documents
- getting the total count
- aggregating (grouping) based on a category — the usual suspect being e-shops facets
In this chapter we'll be specifically focusing on aggregations but before we do that, let's quickly talk about counting.
Prior to v7.x, a
_search request used to yield the exact total. From 7.0 onwards, you'll need to specify
"track_total_hits": true in your
_search payload. If this param is left out, ES will accurately count up only to 10,000 docs and then set the
gte. Stopping at 10K is a good trade-off to speed up searches.