Let my-index-0 be an ES index with an alias of my-index.
It has the following mapping:
{
"my-index-0": {
"aliases": {
"my-index": {}
},
"mappings": {
"doc": {
"properties": {
"foo": {
"properties": {
"fizz": {
"type": "keyword"
},
"baz": {
"type": "keyword"
}
}
}
}
}
}
}
}
Let's say I want to remove the baz
field from foo
. I'm using the following steps:
- Create a new index
my-index-1
with updated mapping (foo.baz
removed) usingPUT /my-index-1
{
"mappings": {
"doc": {
"properties": {
"foo": {
"properties": {
"fizz": {
"type": "keyword"
},
}
}
}
}
}
}
- Reindex data from
my-index-0
tomy-index-1
usingPOST /_reindex
{
"source": {
"index": "my-index-0"
},
"dest": {
"index": "my-index-1"
}
}
- Move the
my-index
alias to themy-index-1
index usingPOST /_aliases
{
"actions": [
{"remove": {"index": "my-index-0", "alias": "my-index"}},
{"add": {"index": "my-index-1", "alias": "my-index"}},
]
}
Expected result
Data in the new index does not have the foo.baz
property.
Actual result
On my-index-1
creation, its mapping does not contain the foo.baz
field, however, after re-indexation, my-index-1
's mapping is changed to the old index' mapping.
Note: _source
can be used for simple fields removal
If one wants to remove a field, for example, removal of bar
from the mapping below
{
"mappings": {
"foo": {
"type": "text"
},
"bar": {
"type": "text"
}
}
}
it is sufficient to provide the _source
param without the bar
field in the request to reindex API:
{
"source": {
"index": "my-index-0",
"_source": ["foo"]
},
"dest": {
"index": "my-index-1"
}
}
How to achieve the same with a nested structure?