elasticsearch/elasticsearch — pull request #1574 by dakrone (2011-12-27 20:56:27+00:00)
Title: Add query validation feature

Hi Shay,

This adds a query validation feature to ElasticSearch, allowing users to validate that potentially expensive queries have correct syntax without actually running them.

It defines a new REST endpoint, `_validate` that validates the query and returns a boolean.

Here is some example usage:

```
% curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}'

% curl -XGET 'http://localhost:9200/twitter/_validate?q=user:foo'
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}

% curl -XGET 'http://localhost:9200/twitter/tweet/_validate?q=post_date:foo'
{"valid":false,"_shards":{"total":1,"successful":1,"failed":0}}

% curl -XGET 'http://localhost:9200/twitter/_validate?q=us:er:foo'
{"valid":false,"_shards":{"total":1,"successful":1,"failed":0}}
```
Or with a request body:

```
% curl -XGET 'http://localhost:9200/twitter/tweet/_validate' -d '{
"query_string":{
"query":"message:foo"
}
}'
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}

% curl -XGET 'http://localhost:9200/twitter/tweet/_validate' -d '{
"filtered" : {
"query" : {
"query_string" : {
"query" : "*:*"
}
},
"filter" : {
"term" : { "user" : "kimchy" }
}
}
}'
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}
```