Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Add response body parms to search API docs #47042

Merged
merged 12 commits into from
Sep 30, 2019
218 changes: 193 additions & 25 deletions docs/reference/search/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
Returns search hits that match the query defined in the request.

[source,console]
--------------------------------------------------
GET /twitter/_search?q=user:kimchy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--------------------------------------------------
----
GET /twitter/_search?q=tag:wow
----
// TEST[setup:twitter]


[[search-search-api-request]]
==== {api-request-title}

`GET /<index>/_search` +
`GET /<index>/_search`

`POST /<index>/_search`

`GET /all/_search`
`GET /_search`

`POST /_search`


[[search-search-api-desc]]
Expand Down Expand Up @@ -214,35 +218,199 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeout]
<<query-dsl,Query DSL>>.


[[search-api-response-body]]
==== {api-response-body-title}

`took`::
+
--
(Integer)
Milliseconds it took {es} to execute the request.

This value is calculated by measuring the time elapsed
between receipt of a request on the coordinating node
and the time at which the coordinating node is ready to send the response.

Took time includes:

* Communication time between the coordinating node and data nodes
* Time the request spends in the `search` <<modules-threadpool,thread pool>>,
queued for execution
* Actual execution time

Took time does *not* include:

* Time needed to send the request to {es}
* Time needed to serialize the JSON response
* Time needed to send the response to a client
--
jrodewig marked this conversation as resolved.
Show resolved Hide resolved


`timed_out`::
+
--
(Boolean)
If `true`,
the request timed out before completion;
returned results may be partial or empty.
--

`_shards`::
+
--
(Object)
Object containing a count of shards used for the request.
Returned parameters include:

`total`::
(Integer)
Total number of shards that require querying,
including unallocated shards.

`successful`::
(Integer)
Number of shards that executed the request successfully.

`skipped`::
(Integer)
Number of shards that skipped the request because a lightweight check
helped realize that no documents could possibly match on this shard. This
typically happens when a search request includes a range filter and the
shard only has values that fall outside of that range.

`failed`::
(Integer)
Number of shards that failed to execute the request. Note that shards
that are not allocated will be considered neither successful nor failed.
Having `failed+successful` less than `total` is thus an indication that
some of the shards were not allocated.

--

`hits`::
+
--
(Object)
Contains returned documents and metadata.
Returned parameters include:

`total`::
(Object)
Metadata about the number of returned documents.
Returned parameters include:
+
* `value`: Total number of returned documents.
* `relation`: Indicates whether the number of documents returned.
Returned values are:
** `eq`: Accurate
** `gte`: Lower bound, including returned documents

`max_score`::
(Float)
Highest returned document `_score`.
+
The `_score` parameter is a floating point number
used to determine the relevance of the returned document.
jrodewig marked this conversation as resolved.
Show resolved Hide resolved
+
This parameter value is `null` for requests
that do not sort by `_score`.

`hits`::
(Array of objects)
Array of returned document objects.
Returned parameters include:
+
* `_index`: Name of the index containing the returned document.
* `_id`: Unique identifier for the returned document.
jrodewig marked this conversation as resolved.
Show resolved Hide resolved
This ID is only unique within the returned index.
* `_score`: Floating point number
used to determine the relevance of the returned document.
* `_source`: Object containing the original JSON body
passed for the document at index time.
--


[[search-search-api-example]]
==== {api-examples-title}

["float",id="search-multi-index"]
===== Multi-Index

All search APIs can be applied across multiple indices with support for
the <<multi-index,multi index syntax>>. For
example, we can search on all documents within the twitter index:
[[search-api-specific-ex]]
===== Search a specific index

[source,console]
--------------------------------------------------
----
GET /twitter/_search?q=user:kimchy
--------------------------------------------------
// TEST[setup:twitter]

We can also search all documents with a certain tag across several indices
(for example, when there is one index per user):
----
// TEST[continued]

The API returns the following response:

[source,console-result]
----
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.3862944,
"hits" : [
{
"_index" : "twitter",
"_id" : "0",
"_score" : 1.3862944,
"_source" : {
"date" : "2009-11-15T14:12:12",
"likes" : 0,
"message" : "trying out Elasticsearch",
"user" : "kimchy"
}
}
]
}
}
----
// TESTRESPONSE[s/"took" : 5/"took": $body.took/]

[[search-multi-index]]
===== Search several indices

[source,console]
--------------------------------------------------
GET /kimchy,elasticsearch/_search?q=tag:wow
--------------------------------------------------
----
GET /kimchy,elasticsearch/_search?q=user:kimchy
----
// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]

Or we can search across all available indices using `_all`:
[[search-api-all-ex]]
===== Search all indices

To search all indices in a cluster,
omit the `<index>` parameter.

[source,console]
---------------------------------------------------
GET /_all/_search?q=tag:wow
---------------------------------------------------
// TEST[setup:twitter]
----
GET /_search?q=user:kimchy
----
// TEST[continued]

Alternatively,
you can use the `_all` or `*` value in the `<index>` parameter.

[source,console]
----
GET /_all/_search?q=user:kimchy
----
// TEST[continued]

[source,console]
----
GET /*/_search?q=user:kimchy
----
// TEST[continued]