2013-08-28 19:24:34 -04:00
|
|
|
[[search-request-body]]
|
2019-07-19 14:35:36 -04:00
|
|
|
=== Request Body Search
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-04 04:52:17 -04:00
|
|
|
Specifies search criteria as request body parameters.
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2019-09-04 04:52:17 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /twitter/_search
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"term" : { "user" : "kimchy" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[setup:twitter]
|
|
|
|
|
|
|
|
|
|
|
|
[[search-request-body-api-request]]
|
|
|
|
==== {api-request-title}
|
|
|
|
|
2020-06-18 08:59:00 -04:00
|
|
|
`GET /<target>/_search
|
2019-09-04 04:52:17 -04:00
|
|
|
{
|
|
|
|
"query": {<parameters>}
|
|
|
|
}`
|
|
|
|
|
|
|
|
|
|
|
|
[[search-request-body-api-desc]]
|
|
|
|
==== {api-description-title}
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
The search request can be executed with a search DSL, which includes the
|
2019-09-04 04:52:17 -04:00
|
|
|
<<query-dsl,Query DSL>>, within its body.
|
|
|
|
|
|
|
|
|
|
|
|
[[search-request-body-api-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
2020-06-18 08:59:00 -04:00
|
|
|
`<target>`::
|
|
|
|
(Optional, string)
|
|
|
|
Comma-separated list or wildcard (`*`) expression of data streams, indices,
|
|
|
|
and index aliases used to limit the request.
|
|
|
|
+
|
|
|
|
To search all data streams and indices in a cluster, omit this parameter or use
|
|
|
|
`_all` or `*`.
|
2019-09-04 04:52:17 -04:00
|
|
|
|
|
|
|
[[search-request-body-api-request-body]]
|
|
|
|
==== {api-request-body-title}
|
|
|
|
|
2020-05-07 11:00:03 -04:00
|
|
|
See the search API's <<search-search-api-request-body,request body parameters>>.
|
2014-08-06 05:54:51 -04:00
|
|
|
|
2019-07-19 14:35:36 -04:00
|
|
|
==== Fast check for any matching docs
|
2015-10-30 12:26:18 -04:00
|
|
|
|
2018-02-12 07:36:33 -05:00
|
|
|
NOTE: `terminate_after` is always applied **after** the `post_filter` and stops
|
|
|
|
the query as well as the aggregation executions when enough hits have been
|
|
|
|
collected on the shard. Though the doc count on aggregations may not reflect
|
|
|
|
the `hits.total` in the response since aggregations are applied **before** the
|
|
|
|
post filtering.
|
|
|
|
|
2015-10-30 12:26:18 -04:00
|
|
|
In case we only want to know if there are any documents matching a
|
|
|
|
specific query, we can set the `size` to `0` to indicate that we are not
|
|
|
|
interested in the search results. Also we can set `terminate_after` to `1`
|
|
|
|
to indicate that the query execution can be terminated whenever the first
|
|
|
|
matching document was found (per shard).
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2015-10-30 12:26:18 -04:00
|
|
|
--------------------------------------------------
|
2018-02-12 07:36:33 -05:00
|
|
|
GET /_search?q=message:number&size=0&terminate_after=1
|
2015-10-30 12:26:18 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// TEST[setup:twitter]
|
2015-10-30 12:26:18 -04:00
|
|
|
|
2019-09-04 04:52:17 -04:00
|
|
|
|
2015-10-30 12:26:18 -04:00
|
|
|
The response will not contain any hits as the `size` was set to `0`. The
|
|
|
|
`hits.total` will be either equal to `0`, indicating that there were no
|
|
|
|
matching documents, or greater than `0` meaning that there were at least
|
|
|
|
as many documents matching the query when it was early terminated.
|
|
|
|
Also if the query was terminated early, the `terminated_early` flag will
|
|
|
|
be set to `true` in the response.
|
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console-result]
|
2015-10-30 12:26:18 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-08-01 08:09:54 -04:00
|
|
|
"took": 3,
|
2015-10-30 12:26:18 -04:00
|
|
|
"timed_out": false,
|
|
|
|
"terminated_early": true,
|
|
|
|
"_shards": {
|
2016-08-01 08:09:54 -04:00
|
|
|
"total": 1,
|
|
|
|
"successful": 1,
|
2017-07-12 16:19:20 -04:00
|
|
|
"skipped" : 0,
|
2015-10-30 12:26:18 -04:00
|
|
|
"failed": 0
|
|
|
|
},
|
|
|
|
"hits": {
|
2018-12-05 13:49:06 -05:00
|
|
|
"total" : {
|
|
|
|
"value": 1,
|
|
|
|
"relation": "eq"
|
|
|
|
},
|
2018-08-22 11:23:54 -04:00
|
|
|
"max_score": null,
|
2015-10-30 12:26:18 -04:00
|
|
|
"hits": []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// TESTRESPONSE[s/"took": 3/"took": $body.took/]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-04 04:52:17 -04:00
|
|
|
|
2017-08-15 02:43:26 -04:00
|
|
|
The `took` time in the response contains the milliseconds that this request
|
|
|
|
took for processing, beginning quickly after the node received the query, up
|
|
|
|
until all search related work is done and before the above JSON is returned
|
|
|
|
to the client. This means it includes the time spent waiting in thread pools,
|
|
|
|
executing a distributed search across the whole cluster and gathering all the
|
|
|
|
results.
|
|
|
|
|
2019-09-04 04:52:17 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/docvalue-fields.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/collapse.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/highlighting.asciidoc[]
|
2013-11-13 10:53:10 -05:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/index-boost.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/inner-hits.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/min-score.asciidoc[]
|
|
|
|
|
|
|
|
include::request/named-queries-and-filters.asciidoc[]
|
2014-01-09 17:20:06 -05:00
|
|
|
|
2013-12-16 06:11:06 -05:00
|
|
|
include::request/post-filter.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/preference.asciidoc[]
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
include::request/rescore.asciidoc[]
|
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/script-fields.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
include::request/scroll.asciidoc[]
|
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/search-after.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/search-type.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/sort.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/source-filtering.asciidoc[]
|
2014-10-13 03:41:55 -04:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/stored-fields.asciidoc[]
|
2016-01-12 11:40:34 -05:00
|
|
|
|
2019-04-09 10:35:25 -04:00
|
|
|
include::request/track-total-hits.asciidoc[]
|