<commit_before>[[search]]
= Search APIs

[partintro]
--

Most search APIs are <<search-multi-index-type,multi-index&#44; multi-type>>, with the
exception of the <<search-explain>> endpoints.

[float]
[[search-routing]]
== Routing

When executing a search, it will be broadcasted to all the index/indices
shards (round robin between replicas). Which shards will be searched on
can be controlled by providing the `routing` parameter. For example,
when indexing tweets, the routing value can be the user name:

[source,js]
--------------------------------------------------
$ curl -XPOST 'http://localhost:9200/twitter/tweet?routing=kimchy' -d '{
    "user" : "kimchy",
    "postDate" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
}
'
--------------------------------------------------

In such a case, if we want to search only on the tweets for a specific
user, we can specify it as the routing, resulting in the search hitting
only the relevant shard:

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
    "query": {
        "filtered" : {
            "query" : {
                "query_string" : {
                    "query" : "some query string here"
                }
            },
            "filter" : {
                "term" : { "user" : "kimchy" }
            }
        }
    }
}
'
--------------------------------------------------

The routing parameter can be multi valued represented as a comma
separated string. This will result in hitting the relevant shards where
the routing values match to.

[float]
[[stats-groups]]
== Stats Groups

A search can be associated with stats groups, which maintains a
statistics aggregation per group. It can later be retrieved using the
<<indices-stats,indices stats>> API
specifically. For example, here is a search body request that associate
the request with two different groups:

[source,js]
--------------------------------------------------
{
    "query" : {
        "match_all" : {}
    },
    "stats" : ["group1", "group2"]
}
--------------------------------------------------

--

include::search/search.asciidoc[]

include::search/uri-request.asciidoc[]

include::search/request-body.asciidoc[]

include::search/search-template.asciidoc[]

include::search/facets.asciidoc[]

include::search/aggregations.asciidoc[]

include::search/suggesters.asciidoc[]

include::search/multi-search.asciidoc[]

include::search/count.asciidoc[]

include::search/validate.asciidoc[]

include::search/explain.asciidoc[]

include::search/percolate.asciidoc[]

include::search/more-like-this.asciidoc[]

include::search/benchmark.asciidoc[]

<commit_msg>Docs: Reorganised the search-shards API docs<commit_after>[[search]]
= Search APIs

[partintro]
--

Most search APIs are <<search-multi-index-type,multi-index&#44; multi-type>>, with the
exception of the <<search-explain>> endpoints.

[float]
[[search-routing]]
== Routing

When executing a search, it will be broadcasted to all the index/indices
shards (round robin between replicas). Which shards will be searched on
can be controlled by providing the `routing` parameter. For example,
when indexing tweets, the routing value can be the user name:

[source,js]
--------------------------------------------------
$ curl -XPOST 'http://localhost:9200/twitter/tweet?routing=kimchy' -d '{
    "user" : "kimchy",
    "postDate" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
}
'
--------------------------------------------------

In such a case, if we want to search only on the tweets for a specific
user, we can specify it as the routing, resulting in the search hitting
only the relevant shard:

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
    "query": {
        "filtered" : {
            "query" : {
                "query_string" : {
                    "query" : "some query string here"
                }
            },
            "filter" : {
                "term" : { "user" : "kimchy" }
            }
        }
    }
}
'
--------------------------------------------------

The routing parameter can be multi valued represented as a comma
separated string. This will result in hitting the relevant shards where
the routing values match to.

[float]
[[stats-groups]]
== Stats Groups

A search can be associated with stats groups, which maintains a
statistics aggregation per group. It can later be retrieved using the
<<indices-stats,indices stats>> API
specifically. For example, here is a search body request that associate
the request with two different groups:

[source,js]
--------------------------------------------------
{
    "query" : {
        "match_all" : {}
    },
    "stats" : ["group1", "group2"]
}
--------------------------------------------------

--

include::search/search.asciidoc[]

include::search/uri-request.asciidoc[]

include::search/request-body.asciidoc[]

include::search/search-template.asciidoc[]

include::request/search-shards.asciidoc[]

include::search/aggregations.asciidoc[]

include::search/facets.asciidoc[]

include::search/suggesters.asciidoc[]

include::search/multi-search.asciidoc[]

include::search/count.asciidoc[]

include::search/validate.asciidoc[]

include::search/explain.asciidoc[]

include::search/percolate.asciidoc[]

include::search/more-like-this.asciidoc[]

include::search/benchmark.asciidoc[]


{'fraction_non_alphanumeric': 0.219534376136777, 'fraction_numerical': 0.009457984721716987, 'mean_word_length': 2.253846153846154, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4203016', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1553, 'n_words': 448}