Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created September 28, 2018 10:06
Show Gist options
  • Save lastday154/b78aabd5b36c038fa6fc3a34c41d12ca to your computer and use it in GitHub Desktop.
Save lastday154/b78aabd5b36c038fa6fc3a34c41d12ca to your computer and use it in GitHub Desktop.
backup ElasticSearch
# Backup ES
## Step 1: Create new index for index you want to backup
PUT /backup_test
```json
{
"mappings": {
"faq": {
"properties": {
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"params": {
"type": "object"
},
"r": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword"
},
"intent": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword"
},
"language": {
"type": "text",
"analyzer": "keyword"
}
}
}
}
}
```
## Step 2: Copy old index to new index
POST /_reindex
```json
{
"source": {
"index": "test"
},
"dest": {
"index": "backup_test"
}
}
```
## Step 3: Delete old index
DELETE /test
## Step 4: Create again old index with new mapping data
PUT /test
```json
{
"mappings": {
"faq": {
"properties": {
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"params": {
"type": "object"
},
"r": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword"
},
"intent": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword"
},
"language": {
"type": "text",
"analyzer": "keyword"
}
}
}
}
}
```
## Step 5: Copy new index back to old index => done, you can choose to keep backup or delete it
POST /_reindex
```json
{
"source": {
"index": "backup_test"
},
"dest": {
"index": "test"
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment