2013-08-28 19:24:34 -04:00
|
|
|
[[search]]
|
|
|
|
= Search APIs
|
|
|
|
|
|
|
|
[partintro]
|
|
|
|
--
|
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
Most search APIs are <<search-multi-index-type,multi-index, multi-type>>, with the
|
2013-10-16 10:31:36 -04:00
|
|
|
exception of the <<search-explain>> endpoints.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2013-09-30 17:32:00 -04:00
|
|
|
[[search-routing]]
|
2013-08-28 19:24:34 -04:00
|
|
|
== Routing
|
|
|
|
|
2015-05-24 08:13:51 -04:00
|
|
|
When executing a search, it will be broadcast to all the index/indices
|
2013-08-28 19:24:34 -04:00
|
|
|
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",
|
2014-01-06 15:58:46 -05:00
|
|
|
"message" : "trying out Elasticsearch"
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
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]
|
2013-09-25 12:17:40 -04:00
|
|
|
[[stats-groups]]
|
2013-08-28 19:24:34 -04:00
|
|
|
== 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[]
|
|
|
|
|
2014-03-24 05:33:13 -04:00
|
|
|
include::search/search-template.asciidoc[]
|
|
|
|
|
2014-07-26 09:05:53 -04:00
|
|
|
include::search/search-shards.asciidoc[]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
include::search/suggesters.asciidoc[]
|
|
|
|
|
|
|
|
include::search/multi-search.asciidoc[]
|
|
|
|
|
|
|
|
include::search/count.asciidoc[]
|
|
|
|
|
2014-07-23 22:54:00 -04:00
|
|
|
include::search/exists.asciidoc[]
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
include::search/validate.asciidoc[]
|
|
|
|
|
|
|
|
include::search/explain.asciidoc[]
|
|
|
|
|
|
|
|
include::search/percolate.asciidoc[]
|
|
|
|
|
2015-04-09 19:14:48 -04:00
|
|
|
include::search/field-stats.asciidoc[]
|