Validating your queries
There are times when you are not in total control of the queries that you send to Elasticsearch. The queries can be generated from multiple criteria making them a monster or even worse. They can be generated by some kind of a wizard which makes it hard to troubleshoot and find the part that is faulty and making the query fail. Because of such use cases, Elasticsearch exposes the Validate API, which helps us validate our queries and diagnose potential problems.
Using the Validate API
The usage of the Validate API is very simple. Instead of sending the query to the _search
REST endpoint, we send it to the _validate/query
one. And that's it. Let's look at the following command:
curl -XGET 'localhost:9200/library/_validate/query?pretty' --data-binary '{ "query" : { "bool" : { "must" : { "term" : { "title" : "crime" } }, "should" : { "...