【发布时间】:2020-02-06 08:13:29
【问题描述】:
有一个类似于下面的 Elasticsearch 映射,我正在尝试使用重新索引 API 对其进行更新。我已经学会了如何使用管道来执行各种操作,例如删除字段或更改类型,但是没有从嵌套类型中删除字段。例如,在descriptions 字段中,我将如何设置管道来删除badfield?
{
"mappings": {
"all": {
"_all": {
"enabled": false
},
"dynamic": "strict",
"properties": {
"address": {
"type": "text"
},
"businessName": {
"type": "text"
},
"descriptions": {
"type": "nested",
"properties": {
"dateSeen": {
"type": "date",
"format": "date_time"
},
"source": {
"type": "text",
},
"value": {
"type": "text"
},
"badfield": {
"type": "text"
}
}
},
"dateAdded": {
"type": "date",
"format": "date_time||date_time_no_millis"
}
}
}
}
}
Documentation on removing a field using the removing fields
顺便说一句,使用 ES 6。
我根据评论设置了一个处理器脚本,并遇到了字段为空的问题,即使它明显存在。
{
"processors": [{
"script": {
"source": """
if (ctx._source.descriptions != null) {
for(item in ctx._source.descriptions) {
item.remove('badfield');
}
}
"""
}
}
]
}
编辑:从脚本中删除 _source 是问题所在,这意味着我不完全了解它的用法,但能够创建一个嵌套字段删除脚本。
【问题讨论】:
-
没听懂。您要取消字段中的数据还是“更新”映射?除非您重新索引索引,否则您将无法更新映射。所以,只是想确认你在找什么
-
当您想从映射中删除字段时,需要重新索引和管道来删除存在的字段和数据。我假设如果该字段是嵌套的,也是可能的,但是管道结构并不那么明显。我将发布一个参考文档来说明。 @AndreyBorisko
标签: elasticsearch