Validating your queries
Do you remember our example with the percolator in Chapter 6, Beyond Searching? The assumption was that the user could generate a query, probably by using some kind of wizard, which was stored in ElasticSearch and used for matching documents. You already know that ElasticSearch has many possibilities and many kinds of queries, and sometimes it is difficult to tell if a query is correct or not. To help with this, ElasticSearch exposes the Validate API.
How to use the Validate API
The Validate API is 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 again at a query that we are already familiar with:
{ "bool" : { "must" : { "term" : { "title" : "crime" } }, "should" : { "range : { "year" : { "from" : 1900, "to" : 2000 } } }, "must_not" : { "term" : { "otitle" : "nothing" } } ...