search.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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, Elasticsearch will pick the "best" copy of the data
  11. based on the <<search-adaptive-replica,adaptive replica selection>> formula.
  12. Which shards will be searched on can also be controlled by providing the
  13. `routing` parameter. For example, when indexing tweets, the routing value can be
  14. the user name:
  15. [source,js]
  16. --------------------------------------------------
  17. POST /twitter/tweet?routing=kimchy
  18. {
  19. "user" : "kimchy",
  20. "postDate" : "2009-11-15T14:12:12",
  21. "message" : "trying out Elasticsearch"
  22. }
  23. --------------------------------------------------
  24. // CONSOLE
  25. In such a case, if we want to search only on the tweets for a specific
  26. user, we can specify it as the routing, resulting in the search hitting
  27. only the relevant shard:
  28. [source,js]
  29. --------------------------------------------------
  30. POST /twitter/_search?routing=kimchy
  31. {
  32. "query": {
  33. "bool" : {
  34. "must" : {
  35. "query_string" : {
  36. "query" : "some query string here"
  37. }
  38. },
  39. "filter" : {
  40. "term" : { "user" : "kimchy" }
  41. }
  42. }
  43. }
  44. }
  45. --------------------------------------------------
  46. // CONSOLE
  47. // TEST[continued]
  48. The routing parameter can be multi valued represented as a comma
  49. separated string. This will result in hitting the relevant shards where
  50. the routing values match to.
  51. [float]
  52. [[search-adaptive-replica]]
  53. == Adaptive Replica Selection
  54. By default, Elasticsearch will use what is called adaptive replica selection.
  55. This allows the coordinating node to send the request to the copy deemed "best"
  56. based on a number of criteria:
  57. - Response time of past requests between the coordinating node and the node
  58. containing the copy of the data
  59. - Time past search requests took to execute on the node containing the data
  60. - The queue size of the search threadpool on the node containing the data
  61. This can be turned off by changing the dynamic cluster setting
  62. `cluster.routing.use_adaptive_replica_selection` from `true` to `false`:
  63. [source,js]
  64. --------------------------------------------------
  65. PUT /_cluster/settings
  66. {
  67. "transient": {
  68. "cluster.routing.use_adaptive_replica_selection": false
  69. }
  70. }
  71. --------------------------------------------------
  72. // CONSOLE
  73. If adaptive replica selection is turned off, searches are sent to the
  74. index/indices shards in a round robin fashion between all copies of the data
  75. (primaries and replicas).
  76. [float]
  77. [[stats-groups]]
  78. == Stats Groups
  79. A search can be associated with stats groups, which maintains a
  80. statistics aggregation per group. It can later be retrieved using the
  81. <<indices-stats,indices stats>> API
  82. specifically. For example, here is a search body request that associate
  83. the request with two different groups:
  84. [source,js]
  85. --------------------------------------------------
  86. POST /_search
  87. {
  88. "query" : {
  89. "match_all" : {}
  90. },
  91. "stats" : ["group1", "group2"]
  92. }
  93. --------------------------------------------------
  94. // CONSOLE
  95. // TEST[setup:twitter]
  96. [float]
  97. [[global-search-timeout]]
  98. == Global Search Timeout
  99. Individual searches can have a timeout as part of the
  100. <<search-request-body>>. Since search requests can originate from many
  101. sources, Elasticsearch has a dynamic cluster-level setting for a global
  102. search timeout that applies to all search requests that do not set a
  103. timeout in the <<search-request-body>>. The default value is no global
  104. timeout. The setting key is `search.default_search_timeout` and can be
  105. set using the <<cluster-update-settings>> endpoints. Setting this value
  106. to `-1` resets the global search timeout to no timeout.
  107. [float]
  108. [[global-search-cancellation]]
  109. == Search Cancellation
  110. Searches can be cancelled using standard <<task-cancellation,task cancellation>>
  111. mechanism. By default, a running search only checks if it is cancelled or
  112. not on segment boundaries, therefore the cancellation can be delayed by large
  113. segments. The search cancellation responsiveness can be improved by setting
  114. the dynamic cluster-level setting `search.low_level_cancellation` to `true`.
  115. However, it comes with an additional overhead of more frequent cancellation
  116. checks that can be noticeable on large fast running search queries. Changing this
  117. setting only affects the searches that start after the change is made.
  118. --
  119. include::search/search.asciidoc[]
  120. include::search/uri-request.asciidoc[]
  121. include::search/request-body.asciidoc[]
  122. include::search/search-template.asciidoc[]
  123. include::search/search-shards.asciidoc[]
  124. include::search/suggesters.asciidoc[]
  125. include::search/multi-search.asciidoc[]
  126. include::search/count.asciidoc[]
  127. include::search/validate.asciidoc[]
  128. include::search/explain.asciidoc[]
  129. include::search/profile.asciidoc[]
  130. include::search/field-caps.asciidoc[]
  131. include::search/rank-eval.asciidoc[]