cross-cluster-search.asciidoc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. [[modules-cross-cluster-search]]
  2. == Cross Cluster Search
  3. beta[]
  4. The _cross cluster search_ feature allows any node to act as a federated client across
  5. multiple clusters. In contrast to the <<modules-tribe,tribe node>> feature, a cross cluster search node won't
  6. join the remote cluster, instead it connects to a remote cluster in a light fashion in order to execute
  7. federated search requests.
  8. Cross cluster search works by configuring a remote cluster in the cluster state and connecting only to a
  9. limited number of nodes in the remote cluster. Each remote cluster is referenced by a name and a list of seed nodes.
  10. When a remote cluster is registered, its cluster state is retrieved from one of the seed nodes so that up to 3
  11. _gateway nodes_ are selected to be connected to as part of upcoming cross cluster search requests.
  12. Cross cluster search requests consist of uni-directional connections from the coordinating node to the previously
  13. selected remote nodes only. It is possible to tag which nodes should be selected through
  14. node attributes (see <<cross-cluster-search-settings>>).
  15. Each node in a cluster that has remote clusters configured connects to one or more _gateway nodes_ and uses
  16. them to federate search requests to the remote cluster.
  17. [float]
  18. === Configuring Cross Cluster Search
  19. Remote clusters can be specified globally using <<cluster-update-settings,cluster settings>>
  20. (which can be updated dynamically), or local to individual nodes using the
  21. `elasticsearch.yml` file.
  22. If a remote cluster is configured via `elasticsearch.yml` only the nodes with
  23. that configuration will be able to connect to the remote cluster. In other
  24. words, federated search requests will have to be sent specifically to those
  25. nodes. Remote clusters set via the <<cluster-update-settings,cluster settings API>>
  26. will be available on every node in the cluster.
  27. [WARNING]
  28. This feature was added as Beta in Elasticsearch `v5.3` with further improvements made in 5.4 and 5.5. It requires gateway eligible nodes to be on `v5.5` onwards.
  29. The `elasticsearch.yml` config file for a _cross cluster search_ node just needs to list the
  30. remote clusters that should be connected to, for instance:
  31. [source,yaml]
  32. --------------------------------
  33. search:
  34. remote:
  35. cluster_one: <1>
  36. seeds: 127.0.0.1:9300
  37. cluster_two: <1>
  38. seeds: 127.0.0.1:9301
  39. --------------------------------
  40. <1> `cluster_one` and `cluster_two` are arbitrary cluster aliases representing the connection to each cluster.
  41. These names are subsequently used to distinguish between local and remote indices.
  42. The equivalent example using the <<cluster-update-settings,cluster settings API>>
  43. to add remote clusters to all nodes in the cluster would look like the
  44. following:
  45. [source,js]
  46. --------------------------------
  47. PUT _cluster/settings
  48. {
  49. "persistent": {
  50. "search": {
  51. "remote": {
  52. "cluster_one": {
  53. "seeds": [
  54. "127.0.0.1:9300"
  55. ]
  56. },
  57. "cluster_two": {
  58. "seeds": [
  59. "127.0.0.1:9301"
  60. ]
  61. }
  62. }
  63. }
  64. }
  65. }
  66. --------------------------------
  67. // CONSOLE
  68. A remote cluster can be deleted from the cluster settings by setting its seeds to `null`:
  69. [source,js]
  70. --------------------------------
  71. PUT _cluster/settings
  72. {
  73. "persistent": {
  74. "search": {
  75. "remote": {
  76. "cluster_one": {
  77. "seeds": null <1>
  78. }
  79. }
  80. }
  81. }
  82. }
  83. --------------------------------
  84. // CONSOLE
  85. <1> `cluster_one` would be removed from the cluster settings, leaving `cluster_two` intact.
  86. [float]
  87. === Using cross cluster search
  88. To search the `twitter` index on remote cluster `cluster_1` the index name must be prefixed with the cluster alias
  89. separated by a `:` character:
  90. [source,js]
  91. --------------------------------------------------
  92. POST /cluster_one:twitter/tweet/_search
  93. {
  94. "query": {
  95. "match_all": {}
  96. }
  97. }
  98. --------------------------------------------------
  99. // CONSOLE
  100. // TEST[skip:we don't have two clusters set up during docs testing]
  101. In contrast to the `tribe` feature cross cluster search can also search indices with the same name on different
  102. clusters:
  103. [source,js]
  104. --------------------------------------------------
  105. POST /cluster_one:twitter,twitter/tweet/_search
  106. {
  107. "query": {
  108. "match_all": {}
  109. }
  110. }
  111. --------------------------------------------------
  112. // CONSOLE
  113. // TEST[skip:we don't have two clusters set up during docs testing]
  114. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  115. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  116. remote index
  117. will be prefixed with their remote cluster name:
  118. [source,js]
  119. --------------------------------------------------
  120. {
  121. "took" : 89,
  122. "timed_out" : false,
  123. "_shards" : {
  124. "total" : 10,
  125. "successful" : 10,
  126. "failed" : 0
  127. },
  128. "hits" : {
  129. "total" : 2,
  130. "max_score" : 1.0,
  131. "hits" : [
  132. {
  133. "_index" : "cluster_one:twitter",
  134. "_type" : "tweet",
  135. "_id" : "1",
  136. "_score" : 1.0,
  137. "_source" : {
  138. "user" : "kimchy",
  139. "postDate" : "2009-11-15T14:12:12",
  140. "message" : "trying out Elasticsearch"
  141. }
  142. },
  143. {
  144. "_index" : "twitter",
  145. "_type" : "tweet",
  146. "_id" : "1",
  147. "_score" : 1.0,
  148. "_source" : {
  149. "user" : "kimchy",
  150. "postDate" : "2009-11-15T14:12:12",
  151. "message" : "trying out Elasticsearch"
  152. }
  153. }
  154. ]
  155. }
  156. }
  157. --------------------------------------------------
  158. // TESTRESPONSE
  159. [float]
  160. [[cross-cluster-search-settings]]
  161. === Cross cluster search settings
  162. `search.remote.connections_per_cluster`::
  163. The number of nodes to connect to per remote cluster. The default is `3`.
  164. `search.remote.initial_connect_timeout`::
  165. The time to wait for remote connections to be established when the node starts. The default is `30s`.
  166. `search.remote.node.attr`::
  167. A node attribute to filter out nodes that are eligible as a gateway node in
  168. the remote cluster. For instance a node can have a node attribute
  169. `node.attr.gateway: true` such that only nodes with this attribute will be
  170. connected to if `search.remote.node.attr` is set to `gateway`.
  171. `search.remote.connect`::
  172. By default, any node in the cluster can act as a cross-cluster client and
  173. connect to remote clusters. The `search.remote.connect` setting can be set
  174. to `false` (defaults to `true`) to prevent certain nodes from connecting to
  175. remote clusters. Cross-cluster search requests must be sent to a node that
  176. is allowed to act as a cross-cluster client.