【发布时间】:2021-10-20 14:13:00
【问题描述】:
让 my-index-0 成为一个别名为 my-index 的 ES 索引。
它有以下映射:
{
"my-index-0": {
"aliases": {
"my-index": {}
},
"mappings": {
"doc": {
"properties": {
"foo": {
"properties": {
"fizz": {
"type": "keyword"
},
"baz": {
"type": "keyword"
}
}
}
}
}
}
}
}
假设我想从foo 中删除baz 字段。我正在使用以下步骤:
- 使用
PUT /my-index-1创建一个新的索引my-index-1并更新映射(删除foo.baz)
{
"mappings": {
"doc": {
"properties": {
"foo": {
"properties": {
"fizz": {
"type": "keyword"
},
}
}
}
}
}
}
- 使用
POST /_reindex将数据从my-index-0重新索引到my-index-1
{
"source": {
"index": "my-index-0"
},
"dest": {
"index": "my-index-1"
}
}
- 使用
POST /_aliases将my-index别名移动到my-index-1索引
{
"actions": [
{"remove": {"index": "my-index-0", "alias": "my-index"}},
{"add": {"index": "my-index-1", "alias": "my-index"}},
]
}
预期结果
新索引中的数据没有foo.baz 属性。
实际结果
在创建my-index-1 时,其映射不包含foo.baz 字段,但是在重新索引后,my-index-1 的映射将更改为旧索引的映射。
注意:_source 可用于简单的字段移除
如果要删除一个字段,例如,从下面的映射中删除bar
{
"mappings": {
"foo": {
"type": "text"
},
"bar": {
"type": "text"
}
}
}
在重新索引 API 的请求中提供不带 bar 字段的 _source 参数就足够了:
{
"source": {
"index": "my-index-0",
"_source": ["foo"]
},
"dest": {
"index": "my-index-1"
}
}
如何用嵌套结构实现相同的效果?
【问题讨论】:
标签: elasticsearch reindex