O'Reilly logo

Elasticsearch Server Second Edition by Marek Rogoziński, Rafał Kuć

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Validating your queries

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.

Using 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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required