⚡ ElasticsearchBook is crafted by Jozef Sorocin (🟢 Book a consulting hour) and powered by:
- Spatialized.io (Elasticsearch & Google Maps consulting)
- in cooperation with Garages-Near-Me.com (Effortless parking across Germany)
From Docs through Counts to Aggregations
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.
Approximate vs Exact Counts
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 total.relation
to gte
. Stopping at 10K is a good trade-off to speed up searches.