cross-cluster-search.asciidoc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. [float]
  8. === Using cross cluster search
  9. Cross-cluster search requires <<modules-remote-clusters,configuring remote clusters>>.
  10. [source,js]
  11. --------------------------------
  12. PUT _cluster/settings
  13. {
  14. "persistent": {
  15. "cluster": {
  16. "remote": {
  17. "cluster_one": {
  18. "seeds": [
  19. "127.0.0.1:9300"
  20. ]
  21. },
  22. "cluster_two": {
  23. "seeds": [
  24. "127.0.0.1:9301"
  25. ]
  26. },
  27. "cluster_three": {
  28. "seeds": [
  29. "127.0.0.1:9302"
  30. ]
  31. }
  32. }
  33. }
  34. }
  35. }
  36. --------------------------------
  37. // CONSOLE
  38. // TEST[setup:host]
  39. // TEST[s/127.0.0.1:9300/\${transport_host}/]
  40. To search the `twitter` index on remote cluster `cluster_one` the index name
  41. must be prefixed with the cluster alias separated by a `:` character:
  42. [source,js]
  43. --------------------------------------------------
  44. GET /cluster_one:twitter/_search
  45. {
  46. "query": {
  47. "match": {
  48. "user": "kimchy"
  49. }
  50. }
  51. }
  52. --------------------------------------------------
  53. // CONSOLE
  54. // TEST[continued]
  55. // TEST[setup:twitter]
  56. [source,js]
  57. --------------------------------------------------
  58. {
  59. "took": 150,
  60. "timed_out": false,
  61. "_shards": {
  62. "total": 1,
  63. "successful": 1,
  64. "failed": 0,
  65. "skipped": 0
  66. },
  67. "_clusters": {
  68. "total": 1,
  69. "successful": 1,
  70. "skipped": 0
  71. },
  72. "hits": {
  73. "total" : {
  74. "value": 1,
  75. "relation": "eq"
  76. },
  77. "max_score": 1,
  78. "hits": [
  79. {
  80. "_index": "cluster_one:twitter",
  81. "_type": "_doc",
  82. "_id": "0",
  83. "_score": 1,
  84. "_source": {
  85. "user": "kimchy",
  86. "date": "2009-11-15T14:12:12",
  87. "message": "trying out Elasticsearch",
  88. "likes": 0
  89. }
  90. }
  91. ]
  92. }
  93. }
  94. --------------------------------------------------
  95. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  96. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  97. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  98. Indices can also be searched with the same name on different clusters:
  99. [source,js]
  100. --------------------------------------------------
  101. GET /cluster_one:twitter,twitter/_search
  102. {
  103. "query": {
  104. "match": {
  105. "user": "kimchy"
  106. }
  107. }
  108. }
  109. --------------------------------------------------
  110. // CONSOLE
  111. // TEST[continued]
  112. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  113. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  114. remote index
  115. will be prefixed with their remote cluster name:
  116. [source,js]
  117. --------------------------------------------------
  118. {
  119. "took": 150,
  120. "timed_out": false,
  121. "num_reduce_phases": 3,
  122. "_shards": {
  123. "total": 2,
  124. "successful": 2,
  125. "failed": 0,
  126. "skipped": 0
  127. },
  128. "_clusters": {
  129. "total": 2,
  130. "successful": 2,
  131. "skipped": 0
  132. },
  133. "hits": {
  134. "total" : {
  135. "value": 2,
  136. "relation": "eq"
  137. },
  138. "max_score": 1,
  139. "hits": [
  140. {
  141. "_index": "cluster_one:twitter",
  142. "_type": "_doc",
  143. "_id": "0",
  144. "_score": 1,
  145. "_source": {
  146. "user": "kimchy",
  147. "date": "2009-11-15T14:12:12",
  148. "message": "trying out Elasticsearch",
  149. "likes": 0
  150. }
  151. },
  152. {
  153. "_index": "twitter",
  154. "_type": "_doc",
  155. "_id": "0",
  156. "_score": 2,
  157. "_source": {
  158. "user": "kimchy",
  159. "date": "2009-11-15T14:12:12",
  160. "message": "trying out Elasticsearch",
  161. "likes": 0
  162. }
  163. }
  164. ]
  165. }
  166. }
  167. --------------------------------------------------
  168. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  169. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  170. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  171. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  172. [float]
  173. === Skipping disconnected clusters
  174. By default all remote clusters that are searched via Cross Cluster Search need to be available when
  175. the search request is executed, otherwise the whole request fails and no search results are returned
  176. despite some of the clusters are available. Remote clusters can be made optional through the
  177. boolean `skip_unavailable` setting, set to `false` by default.
  178. [source,js]
  179. --------------------------------
  180. PUT _cluster/settings
  181. {
  182. "persistent": {
  183. "cluster.remote.cluster_two.skip_unavailable": true <1>
  184. }
  185. }
  186. --------------------------------
  187. // CONSOLE
  188. // TEST[continued]
  189. <1> `cluster_two` is made optional
  190. [source,js]
  191. --------------------------------------------------
  192. GET /cluster_one:twitter,cluster_two:twitter,twitter/_search <1>
  193. {
  194. "query": {
  195. "match": {
  196. "user": "kimchy"
  197. }
  198. }
  199. }
  200. --------------------------------------------------
  201. // CONSOLE
  202. // TEST[continued]
  203. <1> Search against the `twitter` index in `cluster_one`, `cluster_two` and also locally
  204. [source,js]
  205. --------------------------------------------------
  206. {
  207. "took": 150,
  208. "timed_out": false,
  209. "num_reduce_phases": 3,
  210. "_shards": {
  211. "total": 2,
  212. "successful": 2,
  213. "failed": 0,
  214. "skipped": 0
  215. },
  216. "_clusters": { <1>
  217. "total": 3,
  218. "successful": 2,
  219. "skipped": 1
  220. },
  221. "hits": {
  222. "total" : {
  223. "value": 2,
  224. "relation": "eq"
  225. },
  226. "max_score": 1,
  227. "hits": [
  228. {
  229. "_index": "cluster_one:twitter",
  230. "_type": "_doc",
  231. "_id": "0",
  232. "_score": 1,
  233. "_source": {
  234. "user": "kimchy",
  235. "date": "2009-11-15T14:12:12",
  236. "message": "trying out Elasticsearch",
  237. "likes": 0
  238. }
  239. },
  240. {
  241. "_index": "twitter",
  242. "_type": "_doc",
  243. "_id": "0",
  244. "_score": 2,
  245. "_source": {
  246. "user": "kimchy",
  247. "date": "2009-11-15T14:12:12",
  248. "message": "trying out Elasticsearch",
  249. "likes": 0
  250. }
  251. }
  252. ]
  253. }
  254. }
  255. --------------------------------------------------
  256. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  257. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  258. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  259. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  260. <1> The `clusters` section indicates that one cluster was unavailable and got skipped
  261. [float]
  262. [[ccs-reduction]]
  263. === CCS reduction phase
  264. Cross-cluster search requests can be executed in two ways:
  265. - the CCS coordinating node minimizes network round-trips by sending one search
  266. request to each cluster. Each cluster performs the search independently,
  267. reducing and fetching results. Once the CCS node has received all the
  268. responses, it performs another reduction and returns the relevant results back
  269. to the user. This strategy is beneficial when there is network latency between
  270. the CCS coordinating node and the remote clusters involved, which is typically
  271. the case. A single request is sent to each remote cluster, at the cost of
  272. retrieving `from` + `size` already fetched results. This is the default
  273. strategy, used whenever possible. In case a scroll is provided, or inner hits
  274. are requested as part of field collapsing, this strategy is not supported hence
  275. network round-trips cannot be minimized and the following strategy is used
  276. instead.
  277. - the CCS coordinating node sends a <<search-shards,search shards>> request to
  278. each remote cluster, in order to collect information about their corresponding
  279. remote indices involved in the search request and the shards where their data
  280. is located. Once each cluster has responded to such request, the search
  281. executes as if all shards were part of the same cluster. The coordinating node
  282. sends one request to each shard involved, each shard executes the query and
  283. returns its own results which are then reduced (and fetched, depending on the
  284. <<search-request-search-type, search type>>) by the CCS coordinating node.
  285. This strategy may be beneficial whenever there is very low network latency
  286. between the CCS coordinating node and the remote clusters involved, as it
  287. treats all shards the same, at the cost of sending many requests to each remote
  288. cluster, which is problematic in presence of network latency.
  289. The <<search-request-body, search API>> supports the `ccs_minimize_roundtrips`
  290. parameter, which defaults to `true` and can be set to `false` in case
  291. minimizing network round-trips is not desirable.
  292. Note that all the communication between the nodes, regardless of which cluster
  293. they belong to and the selected reduce mode, happens through the
  294. <<modules-transport,transport layer>>.