Skip to content

Instantly share code, notes, and snippets.

@sokil
Last active October 10, 2025 11:50
Show Gist options
  • Save sokil/ec72afe929789ce1ee4b06f8c1ba87bd to your computer and use it in GitHub Desktop.
Save sokil/ec72afe929789ce1ee4b06f8c1ba87bd to your computer and use it in GitHub Desktop.
Elastic change index mapping
# get valid mapping and fix it
GET /test.activity_log_v1
# create new indewx with fixed mapping
PUT /test.activity_log_v2/
{
"mappings": {
"properties": {
"action": {
"type": "keyword"
},
"createdAt": {
"type": "date"
},
"entity": {
"type": "keyword"
},
"entityId": {
"type": "long"
},
"entityName": {
"type": "keyword"
},
"entityState": {
"type": "object",
"enabled": false
},
"userId": {
"type": "long"
}
}
},
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "0"
}
}
}
# reindex from old index to new
POST _reindex
{
"source": {
"index": ["test.activity_log_v1"]
},
"dest": {
"index": "test.activity_log_v2"
}
}
# replace alias
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "test.activity_log_v1", "alias" : "test.activity_log" } },
{ "add" : { "index" : "test.activity_log_v2", "alias" : "test.activity_log" } }
]
}
# drop old
DELETE /test.activity_log_v1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment