cross-cluster-search.asciidoc 5.8 KB

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