1
0

cross-cluster-search.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. A cross cluster search node won't join the remote cluster, instead
  5. 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. cluster:
  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. "cluster": {
  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. "cluster": {
  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. "cluster": {
  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/_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": "_doc",
  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. Indices can also be searched with the same name on different clusters:
  197. [source,js]
  198. --------------------------------------------------
  199. GET /cluster_one:twitter,twitter/_search
  200. {
  201. "query": {
  202. "match": {
  203. "user": "kimchy"
  204. }
  205. }
  206. }
  207. --------------------------------------------------
  208. // CONSOLE
  209. // TEST[continued]
  210. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  211. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  212. remote index
  213. will be prefixed with their remote cluster name:
  214. [source,js]
  215. --------------------------------------------------
  216. {
  217. "took": 150,
  218. "timed_out": false,
  219. "_shards": {
  220. "total": 2,
  221. "successful": 2,
  222. "failed": 0,
  223. "skipped": 0
  224. },
  225. "_clusters": {
  226. "total": 2,
  227. "successful": 2,
  228. "skipped": 0
  229. },
  230. "hits": {
  231. "total": 2,
  232. "max_score": 1,
  233. "hits": [
  234. {
  235. "_index": "cluster_one:twitter",
  236. "_type": "_doc",
  237. "_id": "0",
  238. "_score": 1,
  239. "_source": {
  240. "user": "kimchy",
  241. "date": "2009-11-15T14:12:12",
  242. "message": "trying out Elasticsearch",
  243. "likes": 0
  244. }
  245. },
  246. {
  247. "_index": "twitter",
  248. "_type": "_doc",
  249. "_id": "0",
  250. "_score": 2,
  251. "_source": {
  252. "user": "kimchy",
  253. "date": "2009-11-15T14:12:12",
  254. "message": "trying out Elasticsearch",
  255. "likes": 0
  256. }
  257. }
  258. ]
  259. }
  260. }
  261. --------------------------------------------------
  262. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  263. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  264. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  265. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  266. [float]
  267. === Skipping disconnected clusters
  268. By default all remote clusters that are searched via Cross Cluster Search need to be available when
  269. the search request is executed, otherwise the whole request fails and no search results are returned
  270. despite some of the clusters are available. Remote clusters can be made optional through the
  271. boolean `skip_unavailable` setting, set to `false` by default.
  272. [source,js]
  273. --------------------------------
  274. PUT _cluster/settings
  275. {
  276. "persistent": {
  277. "cluster.remote.cluster_two.skip_unavailable": true <1>
  278. }
  279. }
  280. --------------------------------
  281. // CONSOLE
  282. // TEST[continued]
  283. <1> `cluster_two` is made optional
  284. [source,js]
  285. --------------------------------------------------
  286. GET /cluster_one:twitter,cluster_two:twitter,twitter/_search <1>
  287. {
  288. "query": {
  289. "match": {
  290. "user": "kimchy"
  291. }
  292. }
  293. }
  294. --------------------------------------------------
  295. // CONSOLE
  296. // TEST[continued]
  297. <1> Search against the `twitter` index in `cluster_one`, `cluster_two` and also locally
  298. [source,js]
  299. --------------------------------------------------
  300. {
  301. "took": 150,
  302. "timed_out": false,
  303. "_shards": {
  304. "total": 2,
  305. "successful": 2,
  306. "failed": 0,
  307. "skipped": 0
  308. },
  309. "_clusters": { <1>
  310. "total": 3,
  311. "successful": 2,
  312. "skipped": 1
  313. },
  314. "hits": {
  315. "total": 2,
  316. "max_score": 1,
  317. "hits": [
  318. {
  319. "_index": "cluster_one:twitter",
  320. "_type": "_doc",
  321. "_id": "0",
  322. "_score": 1,
  323. "_source": {
  324. "user": "kimchy",
  325. "date": "2009-11-15T14:12:12",
  326. "message": "trying out Elasticsearch",
  327. "likes": 0
  328. }
  329. },
  330. {
  331. "_index": "twitter",
  332. "_type": "_doc",
  333. "_id": "0",
  334. "_score": 2,
  335. "_source": {
  336. "user": "kimchy",
  337. "date": "2009-11-15T14:12:12",
  338. "message": "trying out Elasticsearch",
  339. "likes": 0
  340. }
  341. }
  342. ]
  343. }
  344. }
  345. --------------------------------------------------
  346. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  347. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  348. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  349. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  350. <1> The `clusters` section indicates that one cluster was unavailable and got skipped
  351. [float]
  352. [[cross-cluster-search-settings]]
  353. === Cross cluster search settings
  354. `cluster.remote.connections_per_cluster`::
  355. The number of nodes to connect to per remote cluster. The default is `3`.
  356. `cluster.remote.initial_connect_timeout`::
  357. The time to wait for remote connections to be established when the node starts. The default is `30s`.
  358. `cluster.remote.node.attr`::
  359. A node attribute to filter out nodes that are eligible as a gateway node in
  360. the remote cluster. For instance a node can have a node attribute
  361. `node.attr.gateway: true` such that only nodes with this attribute will be
  362. connected to if `cluster.remote.node.attr` is set to `gateway`.
  363. `cluster.remote.connect`::
  364. By default, any node in the cluster can act as a cross-cluster client and
  365. connect to remote clusters. The `cluster.remote.connect` setting can be set
  366. to `false` (defaults to `true`) to prevent certain nodes from connecting to
  367. remote clusters. Cross-cluster search requests must be sent to a node that
  368. is allowed to act as a cross-cluster client.
  369. `cluster.remote.${cluster_alias}.skip_unavailable`::
  370. Per cluster boolean setting that allows to skip specific clusters when no
  371. nodes belonging to them are available and they are searched as part of a
  372. cross cluster search request. Default is `false`, meaning that all clusters
  373. are mandatory by default, but they can selectively be made optional by
  374. setting this setting to `true`.
  375. [float]
  376. [[retrieve-remote-clusters-info]]
  377. === Retrieving remote clusters info
  378. The <<cluster-remote-info, Remote Cluster Info API>> allows to retrieve
  379. information about the configured remote clusters, as well as the remote
  380. nodes that the Cross Cluster Search node is connected to.