Skip to content

Commit 0a04365

Browse files
authored
[7.3] [DOCS] Add response body parms to search API docs (#47042) (#47307)
1 parent c925e4e commit 0a04365

File tree

1 file changed

+197
-24
lines changed

1 file changed

+197
-24
lines changed

docs/reference/search/search.asciidoc

Lines changed: 197 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
Returns search hits that match the query defined in the request.
55

66
[source,js]
7-
--------------------------------------------------
8-
GET /twitter/_search?q=user:kimchy
9-
--------------------------------------------------
7+
----
8+
GET /twitter/_search?q=tag:wow
9+
----
1010
// CONSOLE
1111
// TEST[setup:twitter]
1212

1313

1414
[[search-search-api-request]]
1515
==== {api-request-title}
1616

17-
`GET /<index>/_search` +
17+
`GET /<index>/_search`
18+
19+
`POST /<index>/_search`
20+
21+
`GET /_search`
1822

19-
`GET /all/_search`
23+
`POST /_search`
2024

2125

2226
[[search-search-api-desc]]
@@ -215,38 +219,207 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeout]
215219
<<query-dsl,Query DSL>>.
216220

217221

222+
[[search-api-response-body]]
223+
==== {api-response-body-title}
224+
225+
`took`::
226+
+
227+
--
228+
(Integer)
229+
Milliseconds it took {es} to execute the request.
230+
231+
This value is calculated by measuring the time elapsed
232+
between receipt of a request on the coordinating node
233+
and the time at which the coordinating node is ready to send the response.
234+
235+
Took time includes:
236+
237+
* Communication time between the coordinating node and data nodes
238+
* Time the request spends in the `search` <<modules-threadpool,thread pool>>,
239+
queued for execution
240+
* Actual execution time
241+
242+
Took time does *not* include:
243+
244+
* Time needed to send the request to {es}
245+
* Time needed to serialize the JSON response
246+
* Time needed to send the response to a client
247+
--
248+
249+
250+
`timed_out`::
251+
+
252+
--
253+
(Boolean)
254+
If `true`,
255+
the request timed out before completion;
256+
returned results may be partial or empty.
257+
--
258+
259+
`_shards`::
260+
+
261+
--
262+
(Object)
263+
Object containing a count of shards used for the request.
264+
Returned parameters include:
265+
266+
`total`::
267+
(Integer)
268+
Total number of shards that require querying,
269+
including unallocated shards.
270+
271+
`successful`::
272+
(Integer)
273+
Number of shards that executed the request successfully.
274+
275+
`skipped`::
276+
(Integer)
277+
Number of shards that skipped the request because a lightweight check
278+
helped realize that no documents could possibly match on this shard. This
279+
typically happens when a search request includes a range filter and the
280+
shard only has values that fall outside of that range.
281+
282+
`failed`::
283+
(Integer)
284+
Number of shards that failed to execute the request. Note that shards
285+
that are not allocated will be considered neither successful nor failed.
286+
Having `failed+successful` less than `total` is thus an indication that
287+
some of the shards were not allocated.
288+
289+
--
290+
291+
`hits`::
292+
+
293+
--
294+
(Object)
295+
Contains returned documents and metadata.
296+
Returned parameters include:
297+
298+
`total`::
299+
(Object)
300+
Metadata about the number of returned documents.
301+
Returned parameters include:
302+
+
303+
* `value`: Total number of returned documents.
304+
* `relation`: Indicates whether the number of documents returned.
305+
Returned values are:
306+
** `eq`: Accurate
307+
** `gte`: Lower bound, including returned documents
308+
309+
`max_score`::
310+
(Float)
311+
Highest returned document `_score`.
312+
+
313+
The `_score` parameter is a floating point number
314+
used to determine the relevance of the returned document.
315+
+
316+
This parameter value is `null` for requests
317+
that do not sort by `_score`.
318+
319+
`hits`::
320+
(Array of objects)
321+
Array of returned document objects.
322+
Returned parameters include:
323+
+
324+
* `_index`: Name of the index containing the returned document.
325+
* `_type`: Document type.
326+
deprecated:[7.0.0, Types are deprecated and are in the process of being removed. See <<removal-of-types>>.]
327+
* `_id`: Unique identifier for the returned document.
328+
This ID is only unique within the returned index.
329+
* `_score`: Floating point number
330+
used to determine the relevance of the returned document.
331+
* `_source`: Object containing the original JSON body
332+
passed for the document at index time.
333+
--
334+
335+
218336
[[search-search-api-example]]
219337
==== {api-examples-title}
220338

221-
["float",id="search-multi-index"]
222-
===== Multi-Index
223-
224-
All search APIs can be applied across multiple indices with support for
225-
the <<multi-index,multi index syntax>>. For
226-
example, we can search on all documents within the twitter index:
339+
[[search-api-specific-ex]]
340+
===== Search a specific index
227341

228342
[source,js]
229-
--------------------------------------------------
343+
----
230344
GET /twitter/_search?q=user:kimchy
231-
--------------------------------------------------
345+
----
232346
// CONSOLE
233-
// TEST[setup:twitter]
347+
// TEST[continued]
348+
349+
The API returns the following response:
234350

235-
We can also search all documents with a certain tag across several indices
236-
(for example, when there is one index per user):
351+
[source,js]
352+
----
353+
{
354+
"took" : 5,
355+
"timed_out" : false,
356+
"_shards" : {
357+
"total" : 1,
358+
"successful" : 1,
359+
"skipped" : 0,
360+
"failed" : 0
361+
},
362+
"hits" : {
363+
"total" : {
364+
"value" : 1,
365+
"relation" : "eq"
366+
},
367+
"max_score" : 1.3862944,
368+
"hits" : [
369+
{
370+
"_index" : "twitter",
371+
"_type" : "_doc",
372+
"_id" : "0",
373+
"_score" : 1.3862944,
374+
"_source" : {
375+
"date" : "2009-11-15T14:12:12",
376+
"likes" : 0,
377+
"message" : "trying out Elasticsearch",
378+
"user" : "kimchy"
379+
}
380+
}
381+
]
382+
}
383+
}
384+
----
385+
// TESTRESPONSE[s/"took" : 5/"took": $body.took/]
386+
387+
[[search-multi-index]]
388+
===== Search several indices
237389

238390
[source,js]
239-
--------------------------------------------------
240-
GET /kimchy,elasticsearch/_search?q=tag:wow
241-
--------------------------------------------------
391+
----
392+
GET /kimchy,elasticsearch/_search?q=user:kimchy
393+
----
242394
// CONSOLE
243395
// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]
244396

245-
Or we can search across all available indices using `_all`:
397+
[[search-api-all-ex]]
398+
===== Search all indices
399+
400+
To search all indices in a cluster,
401+
omit the `<index>` parameter.
246402

247403
[source,js]
248-
---------------------------------------------------
249-
GET /_all/_search?q=tag:wow
250-
---------------------------------------------------
404+
----
405+
GET /_search?q=user:kimchy
406+
----
251407
// CONSOLE
252-
// TEST[setup:twitter]
408+
// TEST[continued]
409+
410+
Alternatively,
411+
you can use the `_all` or `*` value in the `<index>` parameter.
412+
413+
[source,js]
414+
----
415+
GET /_all/_search?q=user:kimchy
416+
----
417+
// CONSOLE
418+
// TEST[continued]
419+
420+
[source,js]
421+
----
422+
GET /*/_search?q=user:kimchy
423+
----
424+
// CONSOLE
425+
// TEST[continued]

0 commit comments

Comments
 (0)