A leaf query is a simple Elasticsearch Query DSL query that applies one search criterion to document fields or values. Match, term-level, range, and phrase queries are examples. section 8.7.4 section 8.9
Use a leaf query when the search requirement is singular:
- Match text in a field, such as a movie synopsis or book author. section 8.7.4 section 2.5.2
- Match structured values, such as a product type, resolution, price range, year, or rating. section 8.7.4 section 11.3.3
- Place the query inside the search request's query object. section 8.5.1 section 8.7.4
Match a phrase in movie synopses
GET movies/_search { "query": { "match_phrase": { "synopsis": "A meek hobbit from the shire and eight companions" } } } The match_phrase object names the leaf-query type, while synopsis identifies the field searched. The query expresses one criterion. section 8.7.4
A leaf query does not combine multiple clauses. For requirements such as matching a title, excluding a rating, preferring an actor, and filtering another field, wrap several leaf queries in a compound query such as bool. section 8.7.4 section 11.3
Listing 11.3 Finding TVs within a price range
GET products/_search
{
"query": {
"bool": {
"must": [ #1
{
"match": { #2
"product": "TV"
}
},
{
"range": { #3
"price": {
"gte": 700,
"lte": 800
}
}
}
]
}
}
}
Compare three leaf queries—a product match, a resolution term, and a colour terms query—combined with a bool must clause. section 11.3.3
