| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 | [[search]]= Search APIs[partintro]--Most search APIs are <<search-multi-index-type,multi-index, multi-type>>, with theexception of the <<search-explain>> endpoints.[float][[search-routing]]== RoutingWhen executing a search, it will be broadcast to all the index/indicesshards (round robin between replicas). Which shards will be searched oncan be controlled by providing the `routing` parameter. For example,when indexing tweets, the routing value can be the user name:[source,js]--------------------------------------------------POST /twitter/tweet?routing=kimchy{    "user" : "kimchy",    "postDate" : "2009-11-15T14:12:12",    "message" : "trying out Elasticsearch"}--------------------------------------------------// CONSOLEIn such a case, if we want to search only on the tweets for a specificuser, we can specify it as the routing, resulting in the search hittingonly the relevant shard:[source,js]--------------------------------------------------POST /twitter/tweet/_search?routing=kimchy{    "query": {        "bool" : {            "must" : {                "query_string" : {                    "query" : "some query string here"                }            },            "filter" : {                "term" : { "user" : "kimchy" }            }        }    }}--------------------------------------------------// CONSOLE// TEST[continued]The routing parameter can be multi valued represented as a commaseparated string. This will result in hitting the relevant shards wherethe routing values match to.[float][[stats-groups]]== Stats GroupsA search can be associated with stats groups, which maintains astatistics aggregation per group. It can later be retrieved using the<<indices-stats,indices stats>> APIspecifically. For example, here is a search body request that associatethe request with two different groups:[source,js]--------------------------------------------------POST /_search{    "query" : {        "match_all" : {}    },    "stats" : ["group1", "group2"]}--------------------------------------------------// CONSOLE// TEST[setup:twitter][float][[global-search-timeout]]== Global Search TimeoutIndividual searches can have a timeout as part of the<<search-request-body>>. Since search requests can originate from manysources, Elasticsearch has a dynamic cluster-level setting for a globalsearch timeout that applies to all search requests that do not set atimeout in the <<search-request-body>>. The default value is no globaltimeout. The setting key is `search.default_search_timeout` and can beset using the <<cluster-update-settings>> endpoints. Setting this valueto `-1` resets the global search timeout to no timeout.--include::search/search.asciidoc[]include::search/uri-request.asciidoc[]include::search/request-body.asciidoc[]include::search/search-template.asciidoc[]include::search/search-shards.asciidoc[]include::search/suggesters.asciidoc[]include::search/multi-search.asciidoc[]include::search/count.asciidoc[]include::search/validate.asciidoc[]include::search/explain.asciidoc[]include::search/profile.asciidoc[]include::search/percolate.asciidoc[]include::search/field-stats.asciidoc[]
 |