我在弹性搜索文档中有一个数组。我想重命名所有出现的特定值。它有以下映射
{
"products" : {
"mappings" : {
"properties" : {
"inStock" : {
"type" : "long"
},
"name" : {
"type" : "keyword"
},
"price" : {
"type" : "double"
},
"tags" : {
"type" : "keyword"
}
}
}
}
}{
"_index" : "products",
"_type" : "_doc",
"_id" : "100",
"_version" : 6,
"_seq_no" : 5,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "Product A",
"price" : 50,
"inStock" : 5,
"tags" : [
"tagA",
"tagB",
"tagC",
"tagD",
"tagB"
]
}
}我正在寻找一个查询将tagB重命名为其他东西,例如:tagF在所有文档中都有这个匹配的标记。
发布于 2022-01-26 10:42:23
可以用update_by_query替换数组的内容,如下所示。
POST /products/_update_by_query
{
"query": {
"term": {
"tags": {
"value": "tagB"
}
}
},
"script": {
"source": "Collections.replaceAll(ctx._source.tags, params.oldTag, params.newTag);",
"params": {"oldTag": "tagB", "newTag": "tagF"},
"lang": "painless"
}
}https://stackoverflow.com/questions/70862130
复制相似问题