cross-cluster-search.asciidoc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. "_shards": {
  122. "total": 2,
  123. "successful": 2,
  124. "failed": 0,
  125. "skipped": 0
  126. },
  127. "_clusters": {
  128. "total": 2,
  129. "successful": 2,
  130. "skipped": 0
  131. },
  132. "hits": {
  133. "total" : {
  134. "value": 2,
  135. "relation": "eq"
  136. },
  137. "max_score": 1,
  138. "hits": [
  139. {
  140. "_index": "cluster_one:twitter",
  141. "_type": "_doc",
  142. "_id": "0",
  143. "_score": 1,
  144. "_source": {
  145. "user": "kimchy",
  146. "date": "2009-11-15T14:12:12",
  147. "message": "trying out Elasticsearch",
  148. "likes": 0
  149. }
  150. },
  151. {
  152. "_index": "twitter",
  153. "_type": "_doc",
  154. "_id": "0",
  155. "_score": 2,
  156. "_source": {
  157. "user": "kimchy",
  158. "date": "2009-11-15T14:12:12",
  159. "message": "trying out Elasticsearch",
  160. "likes": 0
  161. }
  162. }
  163. ]
  164. }
  165. }
  166. --------------------------------------------------
  167. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  168. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  169. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  170. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  171. [float]
  172. === Skipping disconnected clusters
  173. By default all remote clusters that are searched via Cross Cluster Search need to be available when
  174. the search request is executed, otherwise the whole request fails and no search results are returned
  175. despite some of the clusters are available. Remote clusters can be made optional through the
  176. boolean `skip_unavailable` setting, set to `false` by default.
  177. [source,js]
  178. --------------------------------
  179. PUT _cluster/settings
  180. {
  181. "persistent": {
  182. "cluster.remote.cluster_two.skip_unavailable": true <1>
  183. }
  184. }
  185. --------------------------------
  186. // CONSOLE
  187. // TEST[continued]
  188. <1> `cluster_two` is made optional
  189. [source,js]
  190. --------------------------------------------------
  191. GET /cluster_one:twitter,cluster_two:twitter,twitter/_search <1>
  192. {
  193. "query": {
  194. "match": {
  195. "user": "kimchy"
  196. }
  197. }
  198. }
  199. --------------------------------------------------
  200. // CONSOLE
  201. // TEST[continued]
  202. <1> Search against the `twitter` index in `cluster_one`, `cluster_two` and also locally
  203. [source,js]
  204. --------------------------------------------------
  205. {
  206. "took": 150,
  207. "timed_out": false,
  208. "_shards": {
  209. "total": 2,
  210. "successful": 2,
  211. "failed": 0,
  212. "skipped": 0
  213. },
  214. "_clusters": { <1>
  215. "total": 3,
  216. "successful": 2,
  217. "skipped": 1
  218. },
  219. "hits": {
  220. "total" : {
  221. "value": 2,
  222. "relation": "eq"
  223. },
  224. "max_score": 1,
  225. "hits": [
  226. {
  227. "_index": "cluster_one:twitter",
  228. "_type": "_doc",
  229. "_id": "0",
  230. "_score": 1,
  231. "_source": {
  232. "user": "kimchy",
  233. "date": "2009-11-15T14:12:12",
  234. "message": "trying out Elasticsearch",
  235. "likes": 0
  236. }
  237. },
  238. {
  239. "_index": "twitter",
  240. "_type": "_doc",
  241. "_id": "0",
  242. "_score": 2,
  243. "_source": {
  244. "user": "kimchy",
  245. "date": "2009-11-15T14:12:12",
  246. "message": "trying out Elasticsearch",
  247. "likes": 0
  248. }
  249. }
  250. ]
  251. }
  252. }
  253. --------------------------------------------------
  254. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  255. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  256. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  257. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  258. <1> The `clusters` section indicates that one cluster was unavailable and got skipped