Using a terms set query
The previous query will work very well if you have a fixed number of values via the minimum_should_match
parameter to look for.
The natural evolution of the previous type query is to be able to define the minimum number of terms that should be matched via a related field in the document or via scripting code: the terms set query is able to cover these scenarios.
Getting ready
You will need an up-and-running Elasticsearch installation, as described in the Downloading and installing Elasticsearch recipe of Chapter 1, Getting Started.
To execute these commands, any HTTP client can be used, such as curl (https://curl.haxx.se/), Postman (https://www.getpostman.com/), or similar. I suggest you use the Kibana console, as it provides code completion and better character escaping for Elasticsearch.
How to do it...
To execute a terms query, we will perform the following steps:
- We will define an item mapping for an item entity: