cross-cluster-search.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. The `elasticsearch.yml` config file for a _cross cluster search_ node just needs to list the
  28. remote clusters that should be connected to, for instance:
  29. [source,yaml]
  30. --------------------------------
  31. search:
  32. remote:
  33. cluster_one: <1>
  34. seeds: 127.0.0.1:9300
  35. cluster_two: <1>
  36. seeds: 127.0.0.1:9301
  37. --------------------------------
  38. <1> `cluster_one` and `cluster_two` are arbitrary cluster aliases representing the connection to each cluster.
  39. These names are subsequently used to distinguish between local and remote indices.
  40. The equivalent example using the <<cluster-update-settings,cluster settings API>>
  41. to add remote clusters to all nodes in the cluster would look like the
  42. following:
  43. [source,js]
  44. --------------------------------
  45. PUT _cluster/settings
  46. {
  47. "persistent": {
  48. "search": {
  49. "remote": {
  50. "cluster_one": {
  51. "seeds": [
  52. "127.0.0.1:9300"
  53. ]
  54. },
  55. "cluster_two": {
  56. "seeds": [
  57. "127.0.0.1:9301"
  58. ]
  59. }
  60. }
  61. }
  62. }
  63. }
  64. --------------------------------
  65. // CONSOLE
  66. A remote cluster can be deleted from the cluster settings by setting its seeds to `null`:
  67. [source,js]
  68. --------------------------------
  69. PUT _cluster/settings
  70. {
  71. "persistent": {
  72. "search": {
  73. "remote": {
  74. "cluster_one": {
  75. "seeds": null <1>
  76. }
  77. }
  78. }
  79. }
  80. }
  81. --------------------------------
  82. // CONSOLE
  83. <1> `cluster_one` would be removed from the cluster settings, leaving `cluster_two` intact.
  84. [float]
  85. === Using cross cluster search
  86. To search the `twitter` index on remote cluster `cluster_1` the index name must be prefixed with the cluster alias
  87. separated by a `:` character:
  88. [source,js]
  89. --------------------------------------------------
  90. POST /cluster_one:twitter/tweet/_search
  91. {
  92. "match_all": {}
  93. }
  94. --------------------------------------------------
  95. // CONSOLE
  96. // TEST[skip:we don't have two clusters set up during docs testing]
  97. In contrast to the `tribe` feature cross cluster search can also search indices with the same name on different
  98. clusters:
  99. [source,js]
  100. --------------------------------------------------
  101. POST /cluster_one:twitter,twitter/tweet/_search
  102. {
  103. "match_all": {}
  104. }
  105. --------------------------------------------------
  106. // CONSOLE
  107. // TEST[skip:we don't have two clusters set up during docs testing]
  108. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  109. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  110. remote index
  111. will be prefixed with their remote cluster name:
  112. [source,js]
  113. --------------------------------------------------
  114. {
  115. "took" : 89,
  116. "timed_out" : false,
  117. "_shards" : {
  118. "total" : 10,
  119. "successful" : 10,
  120. "failed" : 0
  121. },
  122. "hits" : {
  123. "total" : 2,
  124. "max_score" : 1.0,
  125. "hits" : [
  126. {
  127. "_index" : "cluster_one:twitter",
  128. "_type" : "tweet",
  129. "_id" : "1",
  130. "_score" : 1.0,
  131. "_source" : {
  132. "user" : "kimchy",
  133. "postDate" : "2009-11-15T14:12:12",
  134. "message" : "trying out Elasticsearch"
  135. }
  136. },
  137. {
  138. "_index" : "twitter",
  139. "_type" : "tweet",
  140. "_id" : "1",
  141. "_score" : 1.0,
  142. "_source" : {
  143. "user" : "kimchy",
  144. "postDate" : "2009-11-15T14:12:12",
  145. "message" : "trying out Elasticsearch"
  146. }
  147. }
  148. ]
  149. }
  150. }
  151. --------------------------------------------------
  152. // TESTRESPONSE
  153. [float]
  154. [[cross-cluster-search-settings]]
  155. === Cross cluster search settings
  156. `search.remote.connections_per_cluster`::
  157. The number of nodes to connect to per remote cluster. The default is `3`.
  158. `search.remote.initial_connect_timeout`::
  159. The time to wait for remote connections to be established when the node starts. The default is `30s`.
  160. `search.remote.node.attr`::
  161. A node attribute to filter out nodes that are eligible as a gateway node in
  162. the remote cluster. For instance a node can have a node attribute
  163. `node.attr.gateway: true` such that only nodes with this attribute will be
  164. connected to if `search.remote.node.attr` is set to `gateway`.
  165. `search.remote.connect`::
  166. By default, any node in the cluster can act as a cross-cluster client and
  167. connect to remote clusters. The `search.remote.connect` setting can be set
  168. to `false` (defaults to `true`) to prevent certain nodes from connecting to
  169. remote clusters. Cross-cluster search requests must be sent to a node that
  170. is allowed to act as a cross-cluster client.