Compound queries
In the Basic queries section of this chapter, we discussed the simplest queries exposed by Elasticsearch. We also talked about the position aware queries called span queries in the Span queries
section. However, the simple ones and the span queries are not the only queries that Elasticsearch provides. The compound queries, as we call them, allow us to connect multiple queries together or alter the behavior of other queries. You may wonder if you need such functionality. Your deployment may not need it, but anything apart from a simple query will probably require compound queries. For example, combining a simple term query with a match_phrase
query to get better search results may be a good candidate for compound queries usage.
The bool query
The bool
query allows us to wrap a virtually unbounded number of queries and connect them with a logical value using one of the following sections:
should
: The query wrapped into this section may or may not match. The number ofshould
...