search.asciidoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. POST /twitter/tweet?routing=kimchy
  17. {
  18. "user" : "kimchy",
  19. "postDate" : "2009-11-15T14:12:12",
  20. "message" : "trying out Elasticsearch"
  21. }
  22. --------------------------------------------------
  23. // CONSOLE
  24. In such a case, if we want to search only on the tweets for a specific
  25. user, we can specify it as the routing, resulting in the search hitting
  26. only the relevant shard:
  27. [source,js]
  28. --------------------------------------------------
  29. POST /twitter/tweet/_search?routing=kimchy
  30. {
  31. "query": {
  32. "bool" : {
  33. "must" : {
  34. "query_string" : {
  35. "query" : "some query string here"
  36. }
  37. },
  38. "filter" : {
  39. "term" : { "user" : "kimchy" }
  40. }
  41. }
  42. }
  43. }
  44. --------------------------------------------------
  45. // CONSOLE
  46. // TEST[continued]
  47. The routing parameter can be multi valued represented as a comma
  48. separated string. This will result in hitting the relevant shards where
  49. the routing values match to.
  50. [float]
  51. [[stats-groups]]
  52. == Stats Groups
  53. A search can be associated with stats groups, which maintains a
  54. statistics aggregation per group. It can later be retrieved using the
  55. <<indices-stats,indices stats>> API
  56. specifically. For example, here is a search body request that associate
  57. the request with two different groups:
  58. [source,js]
  59. --------------------------------------------------
  60. POST /_search
  61. {
  62. "query" : {
  63. "match_all" : {}
  64. },
  65. "stats" : ["group1", "group2"]
  66. }
  67. --------------------------------------------------
  68. // CONSOLE
  69. // TEST[setup:twitter]
  70. [float]
  71. [[global-search-timeout]]
  72. == Global Search Timeout
  73. Individual searches can have a timeout as part of the
  74. <<search-request-body>>. Since search requests can originate from many
  75. sources, Elasticsearch has a dynamic cluster-level setting for a global
  76. search timeout that applies to all search requests that do not set a
  77. timeout in the <<search-request-body>>. The default value is no global
  78. timeout. The setting key is `search.default_search_timeout` and can be
  79. set using the <<cluster-update-settings>> endpoints. Setting this value
  80. to `-1` resets the global search timeout to no timeout.
  81. --
  82. include::search/search.asciidoc[]
  83. include::search/uri-request.asciidoc[]
  84. include::search/request-body.asciidoc[]
  85. include::search/search-template.asciidoc[]
  86. include::search/search-shards.asciidoc[]
  87. include::search/suggesters.asciidoc[]
  88. include::search/multi-search.asciidoc[]
  89. include::search/count.asciidoc[]
  90. include::search/validate.asciidoc[]
  91. include::search/explain.asciidoc[]
  92. include::search/profile.asciidoc[]
  93. include::search/percolate.asciidoc[]
  94. include::search/field-stats.asciidoc[]