opensearch-docs-cn/_replication-plugin/api.md

247 lines
5.8 KiB
Markdown
Raw Normal View History

2021-09-30 19:10:28 -04:00
---
layout: default
title: API
nav_order: 50
---
# Cross-cluster replication API
Use these replication operations to programmatically manage cross-cluster replication.
#### Table of contents
- TOC
{:toc}
## Start replication
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Initiate replication of an index from the leader cluster to the follower cluster. Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
PUT /_plugins/_replication/<follower-index>/_start
{
"leader_alias":"<leader-cluster-name>",
"leader_index":"<index-name>",
"use_roles":{
"leader_cluster_role":"<role-name>",
"follower_cluster_role":"<role-name>"
}
}
```
Specify the following options:
Options | Description | Type | Required
:--- | :--- |:--- |:--- |
2021-10-01 14:43:37 -04:00
`leader_alias` | The name of the leader cluster. This alias is the same as the remote cluster name used to set up a cross-cluster connection. | `string` | Yes
2021-09-30 19:10:28 -04:00
`leader_index` | The index on the leader cluster that you want to replicate. | `string` | Yes
`use_roles` | The roles to use for all subsequent backend replication tasks between the indices. Specify a `leader_cluster_role` and `follower_cluster_role`. See [Map the leader and follower cluster roles]({{site.url}}{{site.baseurl}}/replication-plugin/permissions/#map-the-leader-and-follower-cluster-roles). | `string` | If security plugin is enabled
#### Sample response
```json
{
"acknowledged": true
}
```
## Stop replication
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Terminates replication and converts the follower index to a standard index. Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
POST /_plugins/_replication/<follower-index>/_stop
2021-10-01 14:43:37 -04:00
{}
2021-09-30 19:10:28 -04:00
```
#### Sample response
```json
{
"acknowledged": true
}
```
## Pause replication
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Pauses replication of the leader index. Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
2021-10-01 14:43:37 -04:00
POST /_plugins/_replication/<follower-index>/_pause
{}
2021-09-30 19:10:28 -04:00
```
#### Sample response
```json
{
"acknowledged": true
}
```
## Resume replication
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Resumes replication of the leader index. Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
2021-10-01 14:43:37 -04:00
POST /_plugins/_replication/<follower-index>/_resume
{}
2021-09-30 19:10:28 -04:00
```
#### Sample response
```json
{
"acknowledged": true
}
```
## Get replication status
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Gets the status of index replication. Possible statuses are `SYNCING`, `BOOTSTRAPING`, `PAUSED`, and `REPLICATION NOT IN PROGRESS`. Use the syncing details to measure replication lag. Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
GET /_plugins/_replication/<follower-index>/_status
```
#### Sample response
```json
{
2021-10-01 14:43:37 -04:00
"status" : "SYNCING",
"reason" : "User initiated",
"leader_alias" : "leader-cluster",
"leader_index" : "leader-01",
"follower_index" : "follower-01",
"syncing_details" : {
"leader_checkpoint" : 19,
"follower_checkpoint" : 19,
"seq_no" : 0
}
2021-09-30 19:10:28 -04:00
}
```
2021-10-01 14:43:37 -04:00
To include shard replication details in the response, add the `&verbose=true` parameter.
2021-09-30 19:10:28 -04:00
## Update settings
Introduced 1.1
{: .label .label-purple }
Updates settings on the follower index.
#### Request
```json
PUT /_plugins/_replication/<follower-index>/_update
{
"settings":{
"index.number_of_shards": 4,
"index.number_of_replicas": 2
}
}
```
#### Sample response
```json
{
"acknowledged": true
}
```
## Create replication rule
Introduced 1.1
{: .label .label-purple }
2021-10-01 14:43:37 -04:00
Automatically starts replication on indices matching a specified pattern. If a new index on the leader cluster matches the pattern, OpenSearch automatically creates a follower index and begins replication. You can also use this API to update existing replication rules.
2021-09-30 19:10:28 -04:00
2021-10-01 14:43:37 -04:00
Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
Make sure to note the names of all auto-follow patterns after you create them. The replication plugin currently does not include an API operation to retrieve a list of existing patterns.
{: .tip }
#### Request
```json
POST /_plugins/_replication/_autofollow
{
"leader_alias" : "<leader-cluster-name>",
"name": "<auto-follow-pattern-name>",
"pattern": "<pattern>",
"use_roles":{
"leader_cluster_role": "<role-name>",
"follower_cluster_role": "<role-name>"
}
}
```
Specify the following options:
Options | Description | Type | Required
:--- | :--- |:--- |:--- |
`leader_alias` | The name of the remote cluster to associate the pattern with. | `string` | Yes
`name` | A name for the auto-follow pattern. | `string` | Yes
`pattern` | An array of index patterns to match against indices in the specified leader cluster. Supports wildcard characters. For example, `leader-*`. | `string` | Yes
`use_roles` | The roles to use for all subsequent backend replication tasks between the indices. Specify a `leader_cluster_role` and `follower_cluster_role`. See [Map the leader and follower cluster roles]({{site.url}}{{site.baseurl}}/replication-plugin/permissions/#map-the-leader-and-follower-cluster-roles). | `string` | If security plugin is enabled
#### Sample response
```json
{
"acknowledged": true
}
```
## Delete replication rule
Introduced 1.1
{: .label .label-purple }
Deletes the specified replication rule. This operation prevents any new indices from being replicated but does not stop existing replication that the rule has already initiated.
2021-10-01 14:43:37 -04:00
Send this request to the follower cluster.
2021-09-30 19:10:28 -04:00
#### Request
```json
DELETE /_plugins/_replication/_autofollow
{
"leader_alias" : "<leader-cluster-name>",
"name": "<auto-follow-pattern-name>",
}
```
Specify the following options:
Options | Description | Type | Required
:--- | :--- |:--- |:--- |
`leader_alias` | The name of the remote cluster that the pattern is associated with. | `string` | Yes
`name` | The name of the pattern. | `string` | Yes
#### Sample response
```json
{
"acknowledged": true
}
```