Compound queries
In the Basic queries section of this chapter, we discussed the simplest queries exposed by Elasticsearch. However, the simple ones 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. A simple exercise to determine this would be to combine a simple term
query with a phrase query in order to get better search results.
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
: Thebool
query when wrapped into this section may or may not match—the number ofshould
sections that have to match is controlled by theminimum_should_match
parametermust
: Thebool
query when wrapped into this section must match in order for the document to be returnedmust_not
: Thebool
query when wrapped into this section...