๐Ÿ—„๏ธ

7. Aggregations & Buckets

๐Ÿก Home ๐Ÿ‘ˆ Prev ๐Ÿ‘‰ Next
โšกย  ElasticsearchBook.com is crafted by Jozef Sorocin and powered by:

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 the aggs param aggs is not just an abbreviation โ€” it's also a valid request body parameter interchangeable with aggregations. 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 โ†’
ย 

Already purchased? Sign in here.