| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 | [role="xpack"][testenv="platinum"][[ccr-getting-started]]== Getting started with {ccr}beta[]This getting-started guide for {ccr} shows you how to:* <<ccr-getting-started-remote-cluster,Connect a local cluster to a remote  cluster>>* <<ccr-getting-started-leader-index,Create a leader index>> in a remote cluster* <<ccr-getting-started-follower-index,Create a follower index>> that replicates  a leader index* <<ccr-getting-started-auto-follow,Automatically create follower indices>>[float][[ccr-getting-started-before-you-begin]]=== Before you begin. {stack-gs}/get-started-elastic-stack.html#install-elasticsearch[Install {es}]  on your local and remote clusters.. Obtain a license that includes the {ccr} features. See  https://www.elastic.co/subscriptions[subscriptions] and  <<license-management>>.. If the Elastic {security-features} are enabled in your local and remote  clusters, you need a user that has appropriate authority to perform the steps  in this tutorial.+--[[ccr-getting-started-security]]The {ccr} features use cluster privileges and built-in roles to make it easierto control which users have authority to manage {ccr}.By default, you can perform all of the steps in this tutorial byusing the built-in `elastic` user. However, a password must be set for this userbefore the user can do anything. For information about how to set that password,see <<security-getting-started>>.If you are performing these steps in a production environment, take extra carebecause the `elastic` user has the `superuser` role and you could inadvertentlymake significant changes.Alternatively, you can assign the appropriate privileges to a user ID of yourchoice. On the remote cluster that contains the leader index, a user will needthe `read_ccr` cluster privilege and `monitor` and `read` privileges on theleader index.[source,yml]--------------------------------------------------ccr_user:  cluster:    - read_ccr  indices:    - names: [ 'leader-index' ]      privileges:        - monitor        - read--------------------------------------------------On the local cluster that contains the follower index, the same user will needthe `manage_ccr` cluster privilege and `monitor`, `read`, `write` and`manage_follow_index` privileges on the follower index.[source,yml]--------------------------------------------------ccr_user:  cluster:    - manage_ccr  indices:    - names: [ 'follower-index' ]      privileges:        - monitor        - read        - write        - manage_follow_index--------------------------------------------------If you are managing<<ccr-getting-started-remote-cluster,connecting to the remote cluster>> via thecluster update settings API, you will also need a user with the `all` clusterprivilege.--[float][[ccr-getting-started-remote-cluster]]=== Connecting to a remote clusterThe {ccr} features require that you{ref}/modules-remote-clusters.html[connect your local cluster to a remotecluster]. In this tutorial, we will connect our local cluster to a remotecluster with the cluster alias `leader`.[source,js]--------------------------------------------------PUT /_cluster/settings{  "persistent" : {    "cluster" : {      "remote" : {        "leader" : {          "seeds" : [            "127.0.0.1:9300" <1>          ]        }      }    }  }}--------------------------------------------------// CONSOLE// TEST[setup:host]// TEST[s/127.0.0.1:9300/\${transport_host}/]<1> Specifies the hostname and transport port of a seed node in the remote    cluster.You can verify that the local cluster is successfully connected to the remotecluster.[source,js]--------------------------------------------------GET /_remote/info--------------------------------------------------// CONSOLE// TEST[continued]The API will respond by showing that the local cluster is connected to theremote cluster.[source,js]--------------------------------------------------{  "leader" : {    "seeds" : [      "127.0.0.1:9300"    ],    "connected" : true, <1>    "num_nodes_connected" : 1, <2>    "max_connections_per_cluster" : 3,    "initial_connect_timeout" : "30s",    "skip_unavailable" : false  }}--------------------------------------------------// TESTRESPONSE// TEST[s/127.0.0.1:9300/$body.leader.seeds.0/]// TEST[s/"connected" : true/"connected" : $body.leader.connected/]// TEST[s/"num_nodes_connected" : 1/"num_nodes_connected" : $body.leader.num_nodes_connected/]<1> This shows the local cluster is connected to the remote cluster with cluster    alias `leader`<2> This shows the number of nodes in the remote cluster the local cluster is    connected to.    Alternatively, you can manage remote clusters on the*Management / Elasticsearch / Remote Clusters* page in {kib}:[role="screenshot"]image::ml/images/remote-clusters.jpg["The Remote Clusters page in {kib}"][float][[ccr-getting-started-leader-index]]=== Creating a leader indexLeader indices require a special index setting to ensure that the operationsthat need to be replicated are available when the follower requests them fromthe leader. This setting is used to control how many soft deletes are retained.A _soft delete_ occurs whenever a document is deleted or updated. Soft deletescan be enabled only on new indices created on or after {es} 6.5.0, and enabledby default on new indices created on or after {es} 7.0.0.In the following example, we will create a leader index in the remote cluster:[source,js]--------------------------------------------------PUT /server-metrics{  "settings" : {    "index" : {      "number_of_shards" : 1,      "number_of_replicas" : 0,      "soft_deletes" : {        "retention" : {          "operations" : 1024 <1>        }      }    }  },  "mappings" : {    "properties" : {      "@timestamp" : {        "type" : "date"      },      "accept" : {        "type" : "long"      },      "deny" : {        "type" : "long"      },      "host" : {        "type" : "keyword"      },      "response" : {        "type" : "float"      },      "service" : {        "type" : "keyword"      },      "total" : {        "type" : "long"      }    }  }}--------------------------------------------------// CONSOLE// TEST[continued]<1> Sets that up to 1024 soft deletes will be retained.[float][[ccr-getting-started-follower-index]]=== Creating a follower indexFollower indices are created with the {ref}/ccr-put-follow.html[create followerAPI]. When you create a follower index, you must reference the<<ccr-getting-started-remote-cluster,remote cluster>> and the<<ccr-getting-started-leader-index,leader index>> that you created in the remotecluster.[source,js]--------------------------------------------------PUT /server-metrics-copy/_ccr/follow?wait_for_active_shards=1{  "remote_cluster" : "leader",  "leader_index" : "server-metrics"}--------------------------------------------------// CONSOLE// TEST[continued]//////////////////////////[source,js]--------------------------------------------------{  "follow_index_created" : true,  "follow_index_shards_acked" : true,  "index_following_started" : true}--------------------------------------------------// TESTRESPONSE//////////////////////////Now when you index documents into your leader index, you will see thesedocuments replicated in the follower index. You caninspect the status of replication using the{ref}/ccr-get-follow-stats.html[get follower stats API].//////////////////////////[source,js]--------------------------------------------------POST /server-metrics-copy/_ccr/pause_followPOST /server-metrics-copy/_closePOST /server-metrics-copy/_ccr/unfollow--------------------------------------------------// CONSOLE// TEST[continued]//////////////////////////[float][[ccr-getting-started-auto-follow]]=== Automatically create follower indicesThe <<ccr-auto-follow,auto-follow>> feature in {ccr} helps for time series usecases where you want to follow new indices that are periodically created in theremote cluster (such as daily Beats indices). Auto-following is configured usingthe {ref}/ccr-put-auto-follow-pattern.html[create auto-follow pattern API]. Withan auto-follow pattern, you reference the<<ccr-getting-started-remote-cluster,remote cluster>> that you connected yourlocal cluster to. You must also specify a collection of  patterns that match theindices you want to automatically follow.For example:[source,js]--------------------------------------------------PUT /_ccr/auto_follow/beats{  "remote_cluster" : "leader",  "leader_index_patterns" :  [    "metricbeat-*", <1>    "packetbeat-*" <2>  ],  "follow_index_pattern" : "{{leader_index}}-copy" <3>}--------------------------------------------------// CONSOLE// TEST[continued]<1> Automatically follow new {metricbeat} indices.<2> Automatically follow new {packetbeat} indices.<3> The name of the follower index is derived from the name of the leader index    by adding the suffix `-copy` to the name of the leader index.//////////////////////////[source,js]--------------------------------------------------{  "acknowledged" : true}--------------------------------------------------// TESTRESPONSE////////////////////////////////////////////////////[source,js]--------------------------------------------------DELETE /_ccr/auto_follow/beats--------------------------------------------------// CONSOLE// TEST[continued]//////////////////////////Alternatively, you can manage auto-follow patterns on the*Management / Elasticsearch / Cross Cluster Replication* page in {kib}:[role="screenshot"]image::ml/images/auto-follow-patterns.jpg["The Auto-follow patterns page in {kib}"]
 |