elasticsearch/elasticsearch — pull request #1811 by imotov (2012-03-24 03:18:26+00:00)
Title: add extended validation information

This pull request is adding an extended validation information option to the _validate/query request. By adding **explain=true** to the URL it's now possible to get text of the error message if validation fails or translated query if validation succeeds. Such information is very useful when debugging queries that return unexpected results.

Example of a valid query:

```
$ curl 'localhost:9200/twitter/_validate/query?pretty=true&explain=true' -d '{
"query_string" : {
"query" : "some query string here"
}
}'
```
```
{
"valid" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [ {
"index" : "twitter",
"valid" : true,
"explanation" : "_all:some _all:query _all:string _all:here"
} ]
}
```
Example if an invalid query

```
$ curl 'localhost:9200/twitter/_validate/query?pretty=true&explain=true' -d '{
"query_string" : {
"query" : "missing ("
}
}'
```
```
{
"valid" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [ {
"index" : "twitter",
"valid" : false,
"error" : "org.elasticsearch.index.query.QueryParsingException: [twitter] Failed to parse query [missing (]; org.apache.lucene.queryParser.ParseException: Cannot parse 'missing (': Encountered \"\" at line 1, column 9.\nWas expecting one of:\n ...\n \"+\" ...\n \"-\" ...\n \"(\" ...\n \"*\" ...\n ...\n ...\n ...\n ...\n \"[\" ...\n \"{\" ...\n ...\n ...\n \"*\" ...\n "
} ]
}
```