esql-across-clusters.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. [discrete]
  10. [[esql-ccs-prerequisites]]
  11. ==== Prerequisites
  12. include::{es-ref-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-prereqs]
  13. include::{es-ref-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-gateway-seed-nodes]
  14. include::{es-ref-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-proxy-mode]
  15. [discrete]
  16. [[esql-ccs-security-model]]
  17. ==== Security model
  18. {es} supports two security models for cross-cluster search (CCS):
  19. * <<esql-ccs-security-model-certificate, TLS certificate authentication>>
  20. * <<esql-ccs-security-model-api-key, API key authentication>>
  21. [TIP]
  22. ====
  23. To check which security model is being used to connect your clusters, run `GET _remote/info`.
  24. If you're using the API key authentication method, you'll see the `"cluster_credentials"` key in the response.
  25. ====
  26. [discrete]
  27. [[esql-ccs-security-model-certificate]]
  28. ===== TLS certificate authentication
  29. TLS certificate authentication secures remote clusters with mutual TLS.
  30. This could be the preferred model when a single administrator has full control over both clusters.
  31. We generally recommend that roles and their privileges be identical in both clusters.
  32. Refer to <<remote-clusters-cert, TLS certificate authentication>> for prerequisites and detailed setup instructions.
  33. [discrete]
  34. [[esql-ccs-security-model-api-key]]
  35. ===== API key authentication
  36. [NOTE]
  37. ====
  38. `ENRICH` is *not supported* in this version when using {esql} with the API key based security model.
  39. ====
  40. The following information pertains to using {esql} across clusters with the <<remote-clusters-api-key, *API key based security model*>>. You'll need to follow the steps on that page for the *full setup instructions*. This page only contains additional information specific to {esql}.
  41. API key based cross-cluster search (CCS) enables more granular control over allowed actions between clusters.
  42. This may be the preferred model when you have different administrators for different clusters and want more control over who can access what data. In this model, cluster administrators must explicitly define the access given to clusters and users.
  43. You will need to:
  44. * Create an API key on the *remote cluster* using the <<security-api-create-cross-cluster-api-key,Create cross-cluster API key>> API or using the {kibana-ref}/api-keys.html[Kibana API keys UI].
  45. * Add the API key to the keystore on the *local cluster*, as part of the steps in <<remote-clusters-security-api-key-local-actions,configuring the local cluster>>. All cross-cluster requests from the local cluster are bound by the API key’s privileges.
  46. Using {esql} with the API key based security model requires some additional permissions that may not be needed when using the traditional query DSL based search.
  47. The following example API call creates a role that can query remote indices using {esql} when using the API key based security model.
  48. [source,console]
  49. ----
  50. POST /_security/role/remote1
  51. {
  52. "cluster": ["cross_cluster_search"], <1>
  53. "indices": [
  54. {
  55. "names" : [""], <2>
  56. "privileges": ["read"]
  57. }
  58. ],
  59. "remote_indices": [ <3>
  60. {
  61. "names": [ "logs-*" ],
  62. "privileges": [ "read","read_cross_cluster" ], <4>
  63. "clusters" : ["my_remote_cluster"] <5>
  64. }
  65. ]
  66. }
  67. ----
  68. <1> The `cross_cluster_search` cluster privilege is required for the _local_ cluster.
  69. <2> Typically, users will have permissions to read both local and remote indices. However, for cases where the role is intended to ONLY search the remote cluster, the `read` permission is still required for the local cluster. To provide read access to the local cluster, but disallow reading any indices in the local cluster, the `names` field may be an empty string.
  70. <3> The indices allowed read access to the remote cluster. The configured <<security-api-create-cross-cluster-api-key,cross-cluster API key>> must also allow this index to be read.
  71. <4> The `read_cross_cluster` privilege is always required when using {esql} across clusters with the API key based security model.
  72. <5> The remote clusters to which these privileges apply.
  73. This remote cluster must be configured with a <<security-api-create-cross-cluster-api-key,cross-cluster API key>> and connected to the remote cluster before the remote index can be queried.
  74. Verify connection using the <<cluster-remote-info, Remote cluster info>> API.
  75. You will then need a user or API key with the permissions you created above. The following example API call creates a user with the `remote1` role.
  76. [source,console]
  77. ----
  78. POST /_security/user/remote_user
  79. {
  80. "password" : "<PASSWORD>",
  81. "roles" : [ "remote1" ]
  82. }
  83. ----
  84. Remember that all cross-cluster requests from the local cluster are bound by the cross cluster API key’s privileges, which are controlled by the remote cluster's administrator.
  85. [discrete]
  86. [[ccq-remote-cluster-setup]]
  87. ==== Remote cluster setup
  88. Once the security model is configured, you can add remote clusters.
  89. include::{es-ref-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-remote-cluster-setup]
  90. <1> Since `skip_unavailable` was not set on `cluster_three`, it uses
  91. the default of `false`. See the <<ccq-skip-unavailable-clusters>>
  92. section for details.
  93. [discrete]
  94. [[ccq-from]]
  95. ==== Query across multiple clusters
  96. In the `FROM` command, specify data streams and indices on remote clusters
  97. using the format `<remote_cluster_name>:<target>`. For instance, the following
  98. {esql} request queries the `my-index-000001` index on a single remote cluster
  99. named `cluster_one`:
  100. [source,esql]
  101. ----
  102. FROM cluster_one:my-index-000001
  103. | LIMIT 10
  104. ----
  105. Similarly, this {esql} request queries the `my-index-000001` index from
  106. three clusters:
  107. * The local ("querying") cluster
  108. * Two remote clusters, `cluster_one` and `cluster_two`
  109. [source,esql]
  110. ----
  111. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  112. | LIMIT 10
  113. ----
  114. Likewise, this {esql} request queries the `my-index-000001` index from all
  115. remote clusters (`cluster_one`, `cluster_two`, and `cluster_three`):
  116. [source,esql]
  117. ----
  118. FROM *:my-index-000001
  119. | LIMIT 10
  120. ----
  121. [discrete]
  122. [[ccq-enrich]]
  123. ==== Enrich across clusters
  124. Enrich in {esql} across clusters operates similarly to <<esql-enrich,local enrich>>.
  125. If the enrich policy and its enrich indices are consistent across all clusters, simply
  126. write the enrich command as you would without remote clusters. In this default mode,
  127. {esql} can execute the enrich command on either the local cluster or the remote
  128. clusters, aiming to minimize computation or inter-cluster data transfer. Ensuring that
  129. the policy exists with consistent data on both the local cluster and the remote
  130. clusters is critical for ES|QL to produce a consistent query result.
  131. [NOTE]
  132. ====
  133. Enrich across clusters is *not supported* in this version when using {esql} with the <<remote-clusters-api-key, *API key based security model*>>.
  134. ====
  135. In the following example, the enrich with `hosts` policy can be executed on
  136. either the local cluster or the remote cluster `cluster_one`.
  137. [source,esql]
  138. ----
  139. FROM my-index-000001,cluster_one:my-index-000001
  140. | ENRICH hosts ON ip
  141. | LIMIT 10
  142. ----
  143. Enrich with an {esql} query against remote clusters only can also happen on
  144. the local cluster. This means the below query requires the `hosts` enrich
  145. policy to exist on the local cluster as well.
  146. [source,esql]
  147. ----
  148. FROM cluster_one:my-index-000001,cluster_two:my-index-000001
  149. | LIMIT 10
  150. | ENRICH hosts ON ip
  151. ----
  152. [discrete]
  153. [[esql-enrich-coordinator]]
  154. ===== Enrich with coordinator mode
  155. {esql} provides the enrich `_coordinator` mode to force {esql} to execute the enrich
  156. command on the local cluster. This mode should be used when the enrich policy is
  157. not available on the remote clusters or maintaining consistency of enrich indices
  158. across clusters is challenging.
  159. [source,esql]
  160. ----
  161. FROM my-index-000001,cluster_one:my-index-000001
  162. | ENRICH _coordinator:hosts ON ip
  163. | SORT host_name
  164. | LIMIT 10
  165. ----
  166. [discrete]
  167. [IMPORTANT]
  168. ====
  169. Enrich with the `_coordinator` mode usually increases inter-cluster data transfer and
  170. workload on the local cluster.
  171. ====
  172. [discrete]
  173. [[esql-enrich-remote]]
  174. ===== Enrich with remote mode
  175. {esql} also provides the enrich `_remote` mode to force {esql} to execute the enrich
  176. command independently on each remote cluster where the target indices reside.
  177. This mode is useful for managing different enrich data on each cluster, such as detailed
  178. information of hosts for each region where the target (main) indices contain
  179. log events from these hosts.
  180. In the below example, the `hosts` enrich policy is required to exist on all
  181. remote clusters: the `querying` cluster (as local indices are included),
  182. the remote cluster `cluster_one`, and `cluster_two`.
  183. [source,esql]
  184. ----
  185. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  186. | ENRICH _remote:hosts ON ip
  187. | SORT host_name
  188. | LIMIT 10
  189. ----
  190. A `_remote` enrich cannot be executed after a <<esql-stats-by,stats>>
  191. command. The following example would result in an error:
  192. [source,esql]
  193. ----
  194. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  195. | STATS COUNT(*) BY ip
  196. | ENRICH _remote:hosts ON ip
  197. | SORT host_name
  198. | LIMIT 10
  199. ----
  200. [discrete]
  201. [[esql-multi-enrich]]
  202. ===== Multiple enrich commands
  203. You can include multiple enrich commands in the same query with different
  204. modes. {esql} will attempt to execute them accordingly. For example, this
  205. query performs two enriches, first with the `hosts` policy on any cluster
  206. and then with the `vendors` policy on the local cluster.
  207. [source,esql]
  208. ----
  209. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  210. | ENRICH hosts ON ip
  211. | ENRICH _coordinator:vendors ON os
  212. | LIMIT 10
  213. ----
  214. A `_remote` enrich command can't be executed after a `_coordinator` enrich
  215. command. The following example would result in an error.
  216. [source,esql]
  217. ----
  218. FROM my-index-000001,cluster_one:my-index-000001,cluster_two:my-index-000001
  219. | ENRICH _coordinator:hosts ON ip
  220. | ENRICH _remote:vendors ON os
  221. | LIMIT 10
  222. ----
  223. [discrete]
  224. [[ccq-exclude]]
  225. ==== Excluding clusters or indices from {esql} query
  226. To exclude an entire cluster, prefix the cluster alias with a minus sign in
  227. the `FROM` command, for example: `-my_cluster:*`:
  228. [source,esql]
  229. ----
  230. FROM my-index-000001,cluster*:my-index-000001,-cluster_three:*
  231. | LIMIT 10
  232. ----
  233. To exclude a specific remote index, prefix the index with a minus sign in
  234. the `FROM` command, such as `my_cluster:-my_index`:
  235. [source,esql]
  236. ----
  237. FROM my-index-000001,cluster*:my-index-*,cluster_three:-my-index-000001
  238. | LIMIT 10
  239. ----
  240. [discrete]
  241. [[ccq-skip-unavailable-clusters]]
  242. ==== Optional remote clusters
  243. {ccs-cap} for {esql} currently does not respect the `skip_unavailable`
  244. setting. As a result, if a remote cluster specified in the request is
  245. unavailable or failed, {ccs} for {esql} queries will fail regardless of the setting.
  246. We are actively working to align the behavior of {ccs} for {esql} with other
  247. {ccs} APIs. This includes providing detailed execution information for each cluster
  248. in the response, such as execution time, selected target indices, and shards.
  249. [discrete]
  250. [[ccq-during-upgrade]]
  251. ==== Query across clusters during an upgrade
  252. include::{es-ref-dir}/search/search-your-data/search-across-clusters.asciidoc[tag=ccs-during-upgrade]