Hi @Vikentyi
- get mapping from existing index type and copy it without field to delete; (mapping is created dynamically so I don't know exactly about it and have to ask it for each type)
- create new index with types and put this new mapping
If all your mappings are dynamic then you can skip this step altogether, and just rely on dynamic mappings.
If you want to create mappings yourself, you can just do GET {index}/_mapping
to get all the mappings or GET {index}
to get all the mapping, settings, and aliases in one step. You can use this response as a basis for creating your new index. (You'll need to delete some index settings like created_date
, version.*
, uuid
).
- scroll all documents of existing index types
- index them without deleted field with bulk into new index
You can do this with the reindex API and a script, eg:
POST _reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index"
},
"script": {
"inline": """
if (ctx._type == "bad_type") {
ctx._source.remove("bad_field");
}
"""
}
}
- drop old index
- set alias to new index (i need the same name for index) - there is no way to rename index except to reindex everything again
This can be done in a single atomic step with the update-aliases API:
POST /_aliases
{
"actions": [
{
"add": {
"index": "new_index",
"alias": "old_index"
}
},
{
"remove_index": {
"index": "old_index"
}
}
]
}