esql-across-clusters.asciidoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. [[esql-cross-clusters]]
  2. === Using {esql} across clusters
  3. ++++
  4. <titleabbrev>Using {esql} across clusters</titleabbrev>
  5. ++++
  6. [partintro]
  7. preview::["{ccs-cap} for {esql} is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features."]
  8. With {esql}, you can execute a single query across multiple clusters.
  9. ==== Prerequisites
  10. include::{es-repo-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-prereqs]
  11. include::{es-repo-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-gateway-seed-nodes]
  12. include::{es-repo-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-proxy-mode]
  13. [discrete]
  14. [[ccq-remote-cluster-setup]]
  15. ==== Remote cluster setup
  16. include::{es-repo-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-remote-cluster-setup]
  17. <1> Since `skip_unavailable` was not set on `cluster_three`, it uses
  18. the default of `false`. See the <<ccq-skip-unavailable-clusters>>
  19. section for details.
  20. [discrete]
  21. [[ccq-from]]
  22. ==== Query across multiple clusters
  23. In the `FROM` command, specify data streams and indices on remote clusters
  24. using the format `<remote_cluster_name>:<target>`. For instance, the following
  25. {esql} request queries the `my-index-000001` index on a single remote cluster
  26. named `cluster_one`:
  27. [source,esql]
  28. ----
  29. FROM cluster_one:my-index-000001
  30. | LIMIT 10
  31. ----
  32. Similarly, this {esql} request queries the `my-index-000001` index from
  33. three clusters:
  34. * The local ("querying") cluster
  35. * Two remote clusters, `cluster_one` and `cluster_two`
  36. [source,esql]
  37. ----
  38. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  39. | LIMIT 10
  40. ----
  41. Likewise, this {esql} request queries the `my-index-000001` index from all
  42. remote clusters (`cluster_one`, `cluster_two`, and `cluster_three`):
  43. [source,esql]
  44. ----
  45. FROM *:my-index-000001
  46. | LIMIT 10
  47. ----
  48. [discrete]
  49. [[ccq-enrich]]
  50. ==== Enrich across clusters
  51. Enrich in {esql} across clusters operates similarly to <<esql-enrich,local enrich>>.
  52. If the enrich policy and its enrich indices are consistent across all clusters, simply
  53. write the enrich command as you would without remote clusters. In this default mode,
  54. {esql} can execute the enrich command on either the querying cluster or the fulfilling
  55. clusters, aiming to minimize computation or inter-cluster data transfer. Ensuring that
  56. the policy exists with consistent data on both the querying cluster and the fulfilling
  57. clusters is critical for ES|QL to produce a consistent query result.
  58. In the following example, the enrich with `hosts` policy can be executed on
  59. either the querying cluster or the remote cluster `cluster_one`.
  60. [source,esql]
  61. ----
  62. FROM my-index-000001,cluster_one:my-index-000001
  63. | ENRICH hosts ON ip
  64. | LIMIT 10
  65. ----
  66. Enrich with an {esql} query against remote clusters only can also happen on
  67. the querying cluster. This means the below query requires the `hosts` enrich
  68. policy to exist on the querying cluster as well.
  69. [source,esql]
  70. ----
  71. FROM cluster_one:my-index-000001,cluster_two:my-index-000001
  72. | LIMIT 10
  73. | ENRICH hosts ON ip
  74. ----
  75. [discrete]
  76. [[esql-enrich-coordinator]]
  77. ==== Enrich with coordinator mode
  78. {esql} provides the enrich `_coordinator` mode to force {esql} to execute the enrich
  79. command on the querying cluster. This mode should be used when the enrich policy is
  80. not available on the remote clusters or maintaining consistency of enrich indices
  81. across clusters is challenging.
  82. [source,esql]
  83. ----
  84. FROM my-index-000001,cluster_one:my-index-000001
  85. | ENRICH _coordinator:hosts ON ip
  86. | SORT host_name
  87. | LIMIT 10
  88. ----
  89. [discrete]
  90. [IMPORTANT]
  91. ====
  92. Enrich with the `_coordinator` mode usually increases inter-cluster data transfer and
  93. workload on the querying cluster.
  94. ====
  95. [discrete]
  96. [[esql-enrich-remote]]
  97. ==== Enrich with remote mode
  98. {esql} also provides the enrich `_remote` mode to force {esql} to execute the enrich
  99. command independently on each fulfilling cluster where the target indices reside.
  100. This mode is useful for managing different enrich data on each cluster, such as detailed
  101. information of hosts for each region where the target (main) indices contain
  102. log events from these hosts.
  103. In the below example, the `hosts` enrich policy is required to exist on all
  104. fulfilling clusters: the `querying` cluster (as local indices are included),
  105. the remote cluster `cluster_one`, and `cluster_two`.
  106. [source,esql]
  107. ----
  108. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  109. | ENRICH _remote:hosts ON ip
  110. | SORT host_name
  111. | LIMIT 10
  112. ----
  113. A `_remote` enrich cannot be executed after a <<esql-stats-by,stats>>
  114. command. The following example would result in an error:
  115. [source,esql]
  116. ----
  117. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  118. | STATS COUNT(*) BY ip
  119. | ENRICH _remote:hosts ON ip
  120. | SORT host_name
  121. | LIMIT 10
  122. ----
  123. [discrete]
  124. [[esql-multi-enrich]]
  125. ==== Multiple enrich commands
  126. You can include multiple enrich commands in the same query with different
  127. modes. {esql} will attempt to execute them accordingly. For example, this
  128. query performs two enriches, first with the `hosts` policy on any cluster
  129. and then with the `vendors` policy on the querying cluster.
  130. [source,esql]
  131. ----
  132. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  133. | ENRICH hosts ON ip
  134. | ENRICH _coordinator:vendors ON os
  135. | LIMIT 10
  136. ----
  137. A `_remote` enrich command can't be executed after a `_coordinator` enrich
  138. command. The following example would result in an error.
  139. [source,esql]
  140. ----
  141. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  142. | ENRICH _coordinator:hosts ON ip
  143. | ENRICH _remote:vendors ON os
  144. | LIMIT 10
  145. ----
  146. [discrete]
  147. [[ccq-exclude]]
  148. ==== Excluding clusters or indices from {esql} query
  149. To exclude an entire cluster, prefix the cluster alias with a minus sign in
  150. the `FROM` command, for example: `-my_cluster:*`:
  151. [source,esql]
  152. ----
  153. FROM my-index-000001,cluster*:my-index-000001,-cluster_three:*
  154. | LIMIT 10
  155. ----
  156. To exclude a specific remote index, prefix the index with a minus sign in
  157. the `FROM` command, such as `my_cluster:-my_index`:
  158. [source,esql]
  159. ----
  160. FROM my-index-000001,cluster*:my-index-*,cluster_three:-my-index-000001
  161. | LIMIT 10
  162. ----
  163. [discrete]
  164. [[ccq-skip-unavailable-clusters]]
  165. ==== Optional remote clusters
  166. {ccs-cap} for {esql} currently does not respect the `skip_unavailable`
  167. setting. As a result, if a remote cluster specified in the request is
  168. unavailable or failed, {ccs} for {esql} queries will fail regardless of the setting.
  169. We are actively working to align the behavior of {ccs} for {esql} with other
  170. {ccs} APIs. This includes providing detailed execution information for each cluster
  171. in the response, such as execution time, selected target indices, and shards.
  172. [discrete]
  173. [[ccq-during-upgrade]]
  174. ==== Query across clusters during an upgrade
  175. include::{es-repo-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-during-upgrade]