cross-cluster-search.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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": 1,
  74. "max_score": 1,
  75. "hits": [
  76. {
  77. "_index": "cluster_one:twitter",
  78. "_type": "_doc",
  79. "_id": "0",
  80. "_score": 1,
  81. "_source": {
  82. "user": "kimchy",
  83. "date": "2009-11-15T14:12:12",
  84. "message": "trying out Elasticsearch",
  85. "likes": 0
  86. }
  87. }
  88. ]
  89. }
  90. }
  91. --------------------------------------------------
  92. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  93. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  94. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  95. Indices can also be searched with the same name on different clusters:
  96. [source,js]
  97. --------------------------------------------------
  98. GET /cluster_one:twitter,twitter/_search
  99. {
  100. "query": {
  101. "match": {
  102. "user": "kimchy"
  103. }
  104. }
  105. }
  106. --------------------------------------------------
  107. // CONSOLE
  108. // TEST[continued]
  109. Search results are disambiguated the same way as the indices are disambiguated in the request. Even if index names are
  110. identical these indices will be treated as different indices when results are merged. All results retrieved from a
  111. remote index
  112. will be prefixed with their remote cluster name:
  113. [source,js]
  114. --------------------------------------------------
  115. {
  116. "took": 150,
  117. "timed_out": false,
  118. "_shards": {
  119. "total": 2,
  120. "successful": 2,
  121. "failed": 0,
  122. "skipped": 0
  123. },
  124. "_clusters": {
  125. "total": 2,
  126. "successful": 2,
  127. "skipped": 0
  128. },
  129. "hits": {
  130. "total": 2,
  131. "max_score": 1,
  132. "hits": [
  133. {
  134. "_index": "cluster_one:twitter",
  135. "_type": "_doc",
  136. "_id": "0",
  137. "_score": 1,
  138. "_source": {
  139. "user": "kimchy",
  140. "date": "2009-11-15T14:12:12",
  141. "message": "trying out Elasticsearch",
  142. "likes": 0
  143. }
  144. },
  145. {
  146. "_index": "twitter",
  147. "_type": "_doc",
  148. "_id": "0",
  149. "_score": 2,
  150. "_source": {
  151. "user": "kimchy",
  152. "date": "2009-11-15T14:12:12",
  153. "message": "trying out Elasticsearch",
  154. "likes": 0
  155. }
  156. }
  157. ]
  158. }
  159. }
  160. --------------------------------------------------
  161. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  162. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  163. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  164. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  165. [float]
  166. === Skipping disconnected clusters
  167. By default all remote clusters that are searched via Cross Cluster Search need to be available when
  168. the search request is executed, otherwise the whole request fails and no search results are returned
  169. despite some of the clusters are available. Remote clusters can be made optional through the
  170. boolean `skip_unavailable` setting, set to `false` by default.
  171. [source,js]
  172. --------------------------------
  173. PUT _cluster/settings
  174. {
  175. "persistent": {
  176. "cluster.remote.cluster_two.skip_unavailable": true <1>
  177. }
  178. }
  179. --------------------------------
  180. // CONSOLE
  181. // TEST[continued]
  182. <1> `cluster_two` is made optional
  183. [source,js]
  184. --------------------------------------------------
  185. GET /cluster_one:twitter,cluster_two:twitter,twitter/_search <1>
  186. {
  187. "query": {
  188. "match": {
  189. "user": "kimchy"
  190. }
  191. }
  192. }
  193. --------------------------------------------------
  194. // CONSOLE
  195. // TEST[continued]
  196. <1> Search against the `twitter` index in `cluster_one`, `cluster_two` and also locally
  197. [source,js]
  198. --------------------------------------------------
  199. {
  200. "took": 150,
  201. "timed_out": false,
  202. "_shards": {
  203. "total": 2,
  204. "successful": 2,
  205. "failed": 0,
  206. "skipped": 0
  207. },
  208. "_clusters": { <1>
  209. "total": 3,
  210. "successful": 2,
  211. "skipped": 1
  212. },
  213. "hits": {
  214. "total": 2,
  215. "max_score": 1,
  216. "hits": [
  217. {
  218. "_index": "cluster_one:twitter",
  219. "_type": "_doc",
  220. "_id": "0",
  221. "_score": 1,
  222. "_source": {
  223. "user": "kimchy",
  224. "date": "2009-11-15T14:12:12",
  225. "message": "trying out Elasticsearch",
  226. "likes": 0
  227. }
  228. },
  229. {
  230. "_index": "twitter",
  231. "_type": "_doc",
  232. "_id": "0",
  233. "_score": 2,
  234. "_source": {
  235. "user": "kimchy",
  236. "date": "2009-11-15T14:12:12",
  237. "message": "trying out Elasticsearch",
  238. "likes": 0
  239. }
  240. }
  241. ]
  242. }
  243. }
  244. --------------------------------------------------
  245. // TESTRESPONSE[s/"took": 150/"took": "$body.took"/]
  246. // TESTRESPONSE[s/"max_score": 1/"max_score": "$body.hits.max_score"/]
  247. // TESTRESPONSE[s/"_score": 1/"_score": "$body.hits.hits.0._score"/]
  248. // TESTRESPONSE[s/"_score": 2/"_score": "$body.hits.hits.1._score"/]
  249. <1> The `clusters` section indicates that one cluster was unavailable and got skipped