cross-cluster-search.asciidoc 6.8 KB

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