Last active
October 10, 2025 11:50
-
-
Save sokil/ec72afe929789ce1ee4b06f8c1ba87bd to your computer and use it in GitHub Desktop.
Elastic change index mapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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