Skip to content

Commit db2f4dd

Browse files
szabostevejrodewig
andcommitted
[DOCS] Reformats explain API (elastic#46857)
* [DOCS] Reformats explain API. Co-Authored-By: James Rodewig <[email protected]>
1 parent 68bf677 commit db2f4dd

File tree

1 file changed

+86
-60
lines changed

1 file changed

+86
-60
lines changed

docs/reference/search/explain.asciidoc

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,89 @@
11
[[search-explain]]
22
=== Explain API
33

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
529
document. This can give useful feedback whether a document matches or
630
didn't match a specific query.
731

8-
Note that a single index must be provided to the `index` parameter.
932

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]
1265

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}
1487

1588
[source,js]
1689
--------------------------------------------------
@@ -24,7 +97,8 @@ GET /twitter/_explain/0
2497
// CONSOLE
2598
// TEST[setup:twitter]
2699

27-
This will yield the following result:
100+
101+
The API returns the following response:
28102

29103
[source,js]
30104
--------------------------------------------------
@@ -101,10 +175,11 @@ This will yield the following result:
101175
--------------------------------------------------
102176
// TESTRESPONSE
103177

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:
108183

109184
[source,js]
110185
--------------------------------------------------
@@ -113,54 +188,5 @@ GET /twitter/_explain/0?q=message:search
113188
// CONSOLE
114189
// TEST[setup:twitter]
115190

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.
163191

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

Comments
 (0)