这是我的映射定义。
{
"mappings": {
"properties": {
"title": {
"properties": {
"cell_type": {
"type": "text"
},
"content": {
"type": "text"
}
}
},
"question": {
"properties": {
"cell_type": {
"type": "text"
},
"format": {
"type": "text"
},
"content": {
"type": "text"
}
}
},
"answer": {
"properties": {
"cell_type": {
"type": "text"
},
"format": {
"type": "text"
},
"content": {
"type": "text"
}
}
},
"tags": {
"type": "keyword"
}
}
}
}
我认为在大多数情况下,问题和答案字段都是数组。但是,当格式字段具有多行时,我想避免索引内容字段。因此,我定义了以下管道来删除内容字段。
{
"description": "remove content field",
"processors": [
{
"foreach": {
"field": "question",
"processor": {
"remove": {
"field": "_ingest._value.content",
"if": "ctx.format == 'multiline'"
}
}
}
},
{
"foreach": {
"field": "answer",
"processor": {
"remove": {
"field": "_ingest._value.content",
"field": "ctx.content"
}
}
}
}
]
}
即使格式字段设置为“多行”,该文档仍然具有内容字段。这种情况似乎不符合我的预期。是否可以使用foreach处理器中的任何变量访问内容字段,或者删除问题或答案数组中的内容字段?
我正在使用Elasticsearch 7.8。
最佳答案
我将使用script
处理器代替一个更简单的方法:
{
"description": "remove content field",
"processors": [
{
"script": {
"source": """
ctx.question.stream()
.filter(x -> x.format == 'multiline')
.forEach(x -> x.remove('content'));
ctx.answer.stream()
.filter(x -> x.format == 'multiline')
.forEach(x -> x.remove('content'));
"""
}
}
]
}
关于elasticsearch - 如何删除与foreach处理器中的条件匹配的特定字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62714394/