1
1
[[search-explain]]
2
2
=== Explain API
3
3
4
- The explain api computes a score explanation for a query and a specific
4
+ Returns information about why a specific document matches (or doesn't match) a
5
+ query.
6
+
7
+ [source,console]
8
+ --------------------------------------------------
9
+ GET /twitter/_explain/0
10
+ {
11
+ "query" : {
12
+ "match" : { "message" : "elasticsearch" }
13
+ }
14
+ }
15
+ --------------------------------------------------
16
+ // TEST[setup:twitter]
17
+
18
+
19
+ [[sample-api-request]]
20
+ ==== {api-request-title}
21
+
22
+ `GET /<index>/_explain/<id>`
23
+ `POST /<index>/_explain/<id>`
24
+
25
+ [[sample-api-desc]]
26
+ ==== {api-description-title}
27
+
28
+ The explain API computes a score explanation for a query and a specific
5
29
document. This can give useful feedback whether a document matches or
6
30
didn't match a specific query.
7
31
8
- Note that a single index must be provided to the `index` parameter.
9
32
10
- [float]
11
- ==== Usage
33
+ [[sample-api-path-params]]
34
+ ==== {api-path-parms-title}
35
+
36
+ `<id>`::
37
+ (Required, integer) Defines the document ID.
38
+
39
+ `<index>`::
40
+ +
41
+ --
42
+ (Required, string)
43
+ Index names used to limit the request.
44
+
45
+ Only a single index name can be provided to this parameter.
46
+ --
47
+
48
+
49
+ [[sample-api-query-params]]
50
+ ==== {api-query-parms-title}
51
+
52
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=analyzer]
53
+
54
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=analyze_wildcard]
55
+
56
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=default_operator]
57
+
58
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=df]
59
+
60
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=lenient]
61
+
62
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=preference]
63
+
64
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=search-q]
12
65
13
- Full query example:
66
+ `stored_fields`::
67
+ (Optional, string) A comma-separated list of stored fields to return in the
68
+ response.
69
+
70
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=index-routing]
71
+
72
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=source]
73
+
74
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=source_excludes]
75
+
76
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=source_includes]
77
+
78
+
79
+ [[sample-api-request-body]]
80
+ ==== {api-request-body-title}
81
+
82
+ include::{docdir}/rest-api/common-parms.asciidoc[tag=query]
83
+
84
+
85
+ [[sample-api-example]]
86
+ ==== {api-examples-title}
14
87
15
88
[source,js]
16
89
--------------------------------------------------
@@ -24,7 +97,8 @@ GET /twitter/_explain/0
24
97
// CONSOLE
25
98
// TEST[setup:twitter]
26
99
27
- This will yield the following result:
100
+
101
+ The API returns the following response:
28
102
29
103
[source,js]
30
104
--------------------------------------------------
@@ -101,10 +175,11 @@ This will yield the following result:
101
175
--------------------------------------------------
102
176
// TESTRESPONSE
103
177
104
- There is also a simpler way of specifying the query via the `q`
105
- parameter. The specified `q` parameter value is then parsed as if the
106
- `query_string` query was used. Example usage of the `q` parameter in the
107
- explain api:
178
+
179
+ There is also a simpler way of specifying the query via the `q` parameter. The
180
+ specified `q` parameter value is then parsed as if the `query_string` query was
181
+ used. Example usage of the `q` parameter in the
182
+ explain API:
108
183
109
184
[source,js]
110
185
--------------------------------------------------
@@ -113,54 +188,5 @@ GET /twitter/_explain/0?q=message:search
113
188
// CONSOLE
114
189
// TEST[setup:twitter]
115
190
116
- This will yield the same result as the previous request.
117
-
118
- [float]
119
- ==== All parameters:
120
-
121
- [horizontal]
122
- `_source`::
123
-
124
- Set to `true` to retrieve the `_source` of the document explained. You can also
125
- retrieve part of the document by using `_source_includes` & `_source_excludes` (see <<get-source-filtering,Get API>> for more details)
126
-
127
- `stored_fields`::
128
- Allows to control which stored fields to return as part of the
129
- document explained.
130
-
131
- `routing`::
132
- Controls the routing in the case the routing was used
133
- during indexing.
134
-
135
- `parent`::
136
- Same effect as setting the routing parameter.
137
-
138
- `preference`::
139
- Controls on which shard the explain is executed.
140
-
141
- `source`::
142
- Allows the data of the request to be put in the query
143
- string of the url.
144
-
145
- `q`::
146
- The query string (maps to the query_string query).
147
-
148
- `df`::
149
- The default field to use when no field prefix is defined within
150
- the query.
151
-
152
- `analyzer`::
153
- The analyzer name to be used when analyzing the query
154
- string. Defaults to the default search analyzer.
155
-
156
- `analyze_wildcard`::
157
- Should wildcard and prefix queries be analyzed or
158
- not. Defaults to false.
159
-
160
- `lenient`::
161
- If set to true will cause format based failures (like
162
- providing text to a numeric field) to be ignored. Defaults to false.
163
191
164
- `default_operator`::
165
- The default operator to be used, can be AND or
166
- OR. Defaults to OR.
192
+ The API returns the same result as the previous request.
0 commit comments