โกย 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)
Request Options
As touched upon in 3. Tables & Charts, Elasticsearch supports:
- returning only the original documents by setting
size > 0
- returning both the hits and the aggregations via
size > 0
and specifying theaggs
paramaggs
is not just an abbreviation โ it's also a valid request body parameter interchangeable withaggregations
. On the other hand, the ES response will always include the spelled-out word word "aggregations" never the "aggs" abbreviation.)
ย
An example aggregation request would then look like this:
POST index_name/_search?size=10
{
"size": 0,
"query": {
"bool": { ... }
},
"aggs": {
"agg_name": {
"agg_type": { ... }
}
}
}
Note that the
size
parameter was specified twice โ once as a URI parameter and once as a request body parameter.
It's important to know that the URI parameters always override the request body parameters!Search Contexts
It's tempting to think that since the
query
and aggs
parameters are logically and spatially separated, the query only applies to the hits
. That's wrong.The
query
always affects both the hits
and the aggregations
.The only exception to this rule is explained below.
ย
Facets through global
Aggregations
Sometimes you want to get filtered hits but at the same time prevent the query from affecting the aggregations.
Take e-shop facets. Even when a customer looking for TVs chooses the option
Ultra HD 8K
, we'd want to keep showing the remaining options with correctly updated counts โย