cross-cluster-search.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. "cluster_three": {
  62. "seeds": [
  63. "127.0.0.1:9302"
  64. ]
  65. }
  66. }
  67. }
  68. }
  69. }
  70. --------------------------------
  71. // CONSOLE
  72. // TEST[setup:host]
  73. // TEST[s/127.0.0.1:9300/\${transport_host}/]
  74. //////////////////////////
  75. We want to be sure that settings have been updated,
  76. because we'll use them later.
  77. [source,js]
  78. --------------------------------------------------
  79. {
  80. "acknowledged" : true,
  81. "persistent": {
  82. "search": {
  83. "remote": {
  84. "cluster_one": {
  85. "seeds": [
  86. "127.0.0.1:9300"
  87. ]
  88. },
  89. "cluster_two": {
  90. "seeds": [
  91. "127.0.0.1:9301"
  92. ]
  93. },
  94. "cluster_three": {
  95. "seeds": [
  96. "127.0.0.1:9302"
  97. ]
  98. }
  99. }
  100. }
  101. },
  102. "transient" : {}
  103. }
  104. --------------------------------------------------
  105. // TESTRESPONSE[s/127.0.0.1:9300/\${transport_host}/]
  106. //////////////////////////
  107. A remote cluster can be deleted from the cluster settings by setting its seeds to `null`:
  108. [source,js]
  109. --------------------------------
  110. PUT _cluster/settings
  111. {
  112. "persistent": {
  113. "search": {
  114. "remote": {
  115. "cluster_three": {
  116. "seeds": null <1>
  117. }
  118. }
  119. }
  120. }
  121. }
  122. --------------------------------
  123. // CONSOLE
  124. // TEST[continued]
  125. <1> `cluster_three` would be removed from the cluster settings, leaving `cluster_one` and `cluster_two` intact.
  126. //////////////////////////
  127. We want to be sure that settings have been updated,
  128. because we'll use them later.
  129. [source,js]
  130. --------------------------------------------------
  131. {
  132. "acknowledged" : true,
  133. "persistent" : {},
  134. "transient" : {}
  135. }
  136. --------------------------------------------------
  137. // TESTRESPONSE
  138. //////////////////////////
  139. [float]
  140. === Using cross cluster search
  141. To search the `twitter` index on remote cluster `cluster_one` the index name
  142. must be prefixed with the cluster alias separated by a `:` character:
  143. [source,js]
  144. --------------------------------------------------
  145. GET /cluster_one:twitter/tweet/_search
  146. {
  147. "query": {
  148. "match": {
  149. "user": "kimchy"
  150. }
  151. }
  152. }
  153. --------------------------------------------------
  154. // CONSOLE
  155. // TEST[continued]
  156. // TEST[setup:twitter]
  157. [source,js]
  158. --------------------------------------------------
  159. {
  160. "took": 150,
  161. "timed_out": false,
  162. "_shards": {
  163. "total": 1,
  164. "successful": 1,
  165. "failed": 0,
  166. "skipped": 0
  167. },
  168. "_clusters": {
  169. "total": 1,
  170. "successful": 1,
  171. "skipped": 0
  172. },
  173. "hits": {
  174. "total": 1,
  175. "max_score": 1,
  176. "hits": [
  177. {
  178. "_index": "cluster_one:twitter",
  179. "_type": "tweet",
  180. "_id": "0",
  181. "_score": 1,
  182. "_source": {
  183. "user": "kimchy",
  184. "date": "2009-11-15T14:12:12",
  185. "message": "trying out Elasticsearch",
  186. "likes": 0
  187. }
  188. }
  189. ]
  190. }
  191. }
  192. --------------------------------------------------
  193. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  194. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  195. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  196. In contrast to the `tribe` feature cross cluster search can also search indices with the same name on different
  197. clusters:
  198. [source,js]
  199. --------------------------------------------------
  200. GET /cluster_one:twitter,twitter/tweet/_search
  201. {
  202. "query": {
  203. "match": {
  204. "user": "kimchy"
  205. }
  206. }
  207. }
  208. --------------------------------------------------
  209. // CONSOLE
  210. // TEST[continued]
  211. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  212. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  213. remote index
  214. will be prefixed with their remote cluster name:
  215. [source,js]
  216. --------------------------------------------------
  217. {
  218. "took": 150,
  219. "timed_out": false,
  220. "_shards": {
  221. "total": 2,
  222. "successful": 2,
  223. "failed": 0,
  224. "skipped": 0
  225. },
  226. "_clusters": {
  227. "total": 2,
  228. "successful": 2,
  229. "skipped": 0
  230. },
  231. "hits": {
  232. "total": 2,
  233. "max_score": 1,
  234. "hits": [
  235. {
  236. "_index": "cluster_one:twitter",
  237. "_type": "tweet",
  238. "_id": "0",
  239. "_score": 1,
  240. "_source": {
  241. "user": "kimchy",
  242. "date": "2009-11-15T14:12:12",
  243. "message": "trying out Elasticsearch",
  244. "likes": 0
  245. }
  246. },
  247. {
  248. "_index": "twitter",
  249. "_type": "tweet",
  250. "_id": "0",
  251. "_score": 2,
  252. "_source": {
  253. "user": "kimchy",
  254. "date": "2009-11-15T14:12:12",
  255. "message": "trying out Elasticsearch",
  256. "likes": 0
  257. }
  258. }
  259. ]
  260. }
  261. }
  262. --------------------------------------------------
  263. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  264. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  265. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  266. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  267. [float]
  268. === Skipping disconnected clusters
  269. By default all remote clusters that are searched via Cross Cluster Search need to be available when
  270. the search request is executed, otherwise the whole request fails and no search results are returned
  271. despite some of the clusters are available. Remote clusters can be made optional through the
  272. boolean `skip_unavailable` setting, set to `false` by default.
  273. [source,js]
  274. --------------------------------
  275. PUT _cluster/settings
  276. {
  277. "persistent": {
  278. "search.remote.cluster_two.skip_unavailable": true <1>
  279. }
  280. }
  281. --------------------------------
  282. // CONSOLE
  283. // TEST[continued]
  284. <1> `cluster_two` is made optional
  285. [source,js]
  286. --------------------------------------------------
  287. GET /cluster_one:twitter,cluster_two:twitter,twitter/tweet/_search <1>
  288. {
  289. "query": {
  290. "match": {
  291. "user": "kimchy"
  292. }
  293. }
  294. }
  295. --------------------------------------------------
  296. // CONSOLE
  297. // TEST[continued]
  298. <1> Search against the `twitter` index in `cluster_one`, `cluster_two` and also locally
  299. [source,js]
  300. --------------------------------------------------
  301. {
  302. "took": 150,
  303. "timed_out": false,
  304. "_shards": {
  305. "total": 2,
  306. "successful": 2,
  307. "failed": 0,
  308. "skipped": 0
  309. },
  310. "_clusters": { <1>
  311. "total": 3,
  312. "successful": 2,
  313. "skipped": 1
  314. },
  315. "hits": {
  316. "total": 2,
  317. "max_score": 1,
  318. "hits": [
  319. {
  320. "_index": "cluster_one:twitter",
  321. "_type": "tweet",
  322. "_id": "0",
  323. "_score": 1,
  324. "_source": {
  325. "user": "kimchy",
  326. "date": "2009-11-15T14:12:12",
  327. "message": "trying out Elasticsearch",
  328. "likes": 0
  329. }
  330. },
  331. {
  332. "_index": "twitter",
  333. "_type": "tweet",
  334. "_id": "0",
  335. "_score": 2,
  336. "_source": {
  337. "user": "kimchy",
  338. "date": "2009-11-15T14:12:12",
  339. "message": "trying out Elasticsearch",
  340. "likes": 0
  341. }
  342. }
  343. ]
  344. }
  345. }
  346. --------------------------------------------------
  347. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  348. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  349. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  350. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  351. <1> The `clusters` section indicates that one cluster was unavailable and got skipped
  352. [float]
  353. [[cross-cluster-search-settings]]
  354. === Cross cluster search settings
  355. `search.remote.connections_per_cluster`::
  356. The number of nodes to connect to per remote cluster. The default is `3`.
  357. `search.remote.initial_connect_timeout`::
  358. The time to wait for remote connections to be established when the node starts. The default is `30s`.
  359. `search.remote.node.attr`::
  360. A node attribute to filter out nodes that are eligible as a gateway node in
  361. the remote cluster. For instance a node can have a node attribute
  362. `node.attr.gateway: true` such that only nodes with this attribute will be
  363. connected to if `search.remote.node.attr` is set to `gateway`.
  364. `search.remote.connect`::
  365. By default, any node in the cluster can act as a cross-cluster client and
  366. connect to remote clusters. The `search.remote.connect` setting can be set
  367. to `false` (defaults to `true`) to prevent certain nodes from connecting to
  368. remote clusters. Cross-cluster search requests must be sent to a node that
  369. is allowed to act as a cross-cluster client.
  370. `search.remote.${cluster_alias}.skip_unavailable`::
  371. Per cluster boolean setting that allows to skip specific clusters when no
  372. nodes belonging to them are available and they are searched as part of a
  373. cross cluster search request. Default is `false`, meaning that all clusters
  374. are mandatory by default, but they can selectively be made optional by
  375. setting this setting to `true`.
  376. [float]
  377. [[retrieve-remote-clusters-info]]
  378. === Retrieving remote clusters info
  379. The <<cluster-remote-info, Remote Cluster Info API>> allows to retrieve
  380. information about the configured remote clusters, as well as the remote
  381. nodes that the Cross Cluster Search node is connected to.