esql-across-clusters.asciidoc 12 KB

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