search.asciidoc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. [[search]]
  2. = Search APIs
  3. [partintro]
  4. --
  5. Most search APIs are <<search-multi-index-type,multi-index&#44; multi-type>>, with the
  6. exception of the <<search-explain>> endpoints.
  7. [float]
  8. [[search-routing]]
  9. == Routing
  10. When executing a search, it will be broadcast to all the index/indices
  11. shards (round robin between replicas). Which shards will be searched on
  12. can be controlled by providing the `routing` parameter. For example,
  13. when indexing tweets, the routing value can be the user name:
  14. [source,js]
  15. --------------------------------------------------
  16. $ curl -XPOST 'http://localhost:9200/twitter/tweet?routing=kimchy' -d '{
  17. "user" : "kimchy",
  18. "postDate" : "2009-11-15T14:12:12",
  19. "message" : "trying out Elasticsearch"
  20. }
  21. '
  22. --------------------------------------------------
  23. In such a case, if we want to search only on the tweets for a specific
  24. user, we can specify it as the routing, resulting in the search hitting
  25. only the relevant shard:
  26. [source,js]
  27. --------------------------------------------------
  28. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
  29. "query": {
  30. "filtered" : {
  31. "query" : {
  32. "query_string" : {
  33. "query" : "some query string here"
  34. }
  35. },
  36. "filter" : {
  37. "term" : { "user" : "kimchy" }
  38. }
  39. }
  40. }
  41. }
  42. '
  43. --------------------------------------------------
  44. The routing parameter can be multi valued represented as a comma
  45. separated string. This will result in hitting the relevant shards where
  46. the routing values match to.
  47. [float]
  48. [[stats-groups]]
  49. == Stats Groups
  50. A search can be associated with stats groups, which maintains a
  51. statistics aggregation per group. It can later be retrieved using the
  52. <<indices-stats,indices stats>> API
  53. specifically. For example, here is a search body request that associate
  54. the request with two different groups:
  55. [source,js]
  56. --------------------------------------------------
  57. {
  58. "query" : {
  59. "match_all" : {}
  60. },
  61. "stats" : ["group1", "group2"]
  62. }
  63. --------------------------------------------------
  64. --
  65. include::search/search.asciidoc[]
  66. include::search/uri-request.asciidoc[]
  67. include::search/request-body.asciidoc[]
  68. include::search/search-template.asciidoc[]
  69. include::search/search-shards.asciidoc[]
  70. include::search/suggesters.asciidoc[]
  71. include::search/multi-search.asciidoc[]
  72. include::search/count.asciidoc[]
  73. include::search/exists.asciidoc[]
  74. include::search/validate.asciidoc[]
  75. include::search/explain.asciidoc[]
  76. include::search/percolate.asciidoc[]
  77. include::search/field-stats.asciidoc[]