我在彈性搜索檔案中有一個陣列。我想重命名所有出現的特定值。它具有以下映射
{
"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在所有具有此匹配標簽的檔案中。
uj5u.com熱心網友回復:
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://www.uj5u.com/ruanti/423052.html
標籤:
