Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a89f54a

Browse files
committed
Add 'validate' documentation to the API guide
1 parent 8181ca9 commit a89f54a

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

_layouts/guide.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h3>Core</h3>
2020
<li><a href="/guide/reference/api/count.html">Count</a></li>
2121
<li><a href="/guide/reference/api/delete-by-query.html">Delete By Query</a></li>
2222
<li><a href="/guide/reference/api/more-like-this.html">More Like This</a></li>
23+
<li><a href="/guide/reference/api/validate.html">Validate</a></li>
2324
</ul>
2425

2526
<h3>Indices</h3>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
layout: guide
3+
title: Validate API
4+
cat: guide
5+
sidebar: reference_api
6+
---
7+
8+
p. The validate API allows a user to validate a potentially expensive query without executing it. The following example shows how it can be used:
9+
10+
<pre class="prettyprint">
11+
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
12+
"user" : "kimchy",
13+
"post_date" : "2009-11-15T14:12:12",
14+
"message" : "trying out Elastic Search"
15+
}'
16+
17+
</pre>
18+
19+
When the query is valid, the response contains @valid:true@:
20+
21+
<pre class="prettyprint">
22+
curl -XGET 'http://localhost:9200/twitter/_validate/query?q=user:foo'
23+
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}
24+
</pre>
25+
26+
Or, with a request body:
27+
28+
<pre class="prettyprint">
29+
curl -XGET 'http://localhost:9200/twitter/tweet/_validate/query' -d '{
30+
"filtered" : {
31+
"query" : {
32+
"query_string" : {
33+
"query" : "*:*"
34+
}
35+
},
36+
"filter" : {
37+
"term" : { "user" : "kimchy" }
38+
}
39+
}
40+
}'
41+
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}
42+
</pre>
43+
44+
If the query is invalid, 'valid' will be false. Here the query is invalid because ElasticSearch knows the post_date field should be a date due to dynamic mapping, and 'foo' does not correctly parse into a date:
45+
46+
<pre class="prettyprint">
47+
curl -XGET 'http://localhost:9200/twitter/tweet/_validate/query?q=post_date:foo'
48+
{"valid":false,"_shards":{"total":1,"successful":1,"failed":0}}
49+
</pre>
50+
51+
An @explain@ parameter can be specified to get more detailed information about why a query failed:
52+
53+
<pre class="prettyprint">
54+
curl -XGET 'http://localhost:9200/twitter/tweet/_validate/query?q=post_date:foo&pretty=true&explain=true'
55+
{
56+
"valid" : false,
57+
"_shards" : {
58+
"total" : 1,
59+
"successful" : 1,
60+
"failed" : 0
61+
},
62+
"explanations" : [ {
63+
"index" : "twitter",
64+
"valid" : false,
65+
"error" : "org.elasticsearch.index.query.QueryParsingException: [twitter] Failed to parse; org.elasticsearch.ElasticSearchParseException: failed to parse date field [foo], tried both date format [dateOptionalTime], and timestamp number; java.lang.IllegalArgumentException: Invalid format: \"foo\""
66+
} ]
67+
}
68+
</pre>

0 commit comments

Comments
 (0)