Sometimes, the queries that your application sends to Elasticsearch are generated automatically from multiple criteria or even worse; they are generated by some kind of wizard, where the end user can create complicated queries. The issue is that sometimes it is not easy to tell if the query is correct or not. To help with this, Elasticsearch exposes the validate API.
The validate API is very simple. Instead of sending the query to the _search
endpoint, we send it to the _validate/query
endpoint. And that's it. Let's look at the following query:
{ "query" : { "bool" : { "must" : { "term" : { "title" : "crime" } }, "should" : { "range : { "year" : { "from" : 1900, "to" : 2000 } } }, "must_not" : { "term" : { "otitle" : "nothing" } } } } }