![](/img/trans.png)
[英]How to get nested documents by field value from other documents (ElasticSearch)?
[英]ElasticSearch - Copy one field value to other field for all documents
我們在索引中有一個字段“name”。 我們最近添加了一個新字段“別名”。 我想將名稱字段值復制到所有文檔的新字段別名。
是否有任何更新查詢將執行此操作? 如果那是不可能的,請幫助我實現這一目標。 提前致謝
我正在嘗試此查詢http:// URL / index / profile / _update_by_query
{
"query": {
"constant_score" : {
"filter" : {
"exists" : { "field" : "name" }
}
}
},
"script" : "ctx._source.alias = name;"
}
在腳本中,我不知道如何給名字字段。 我收到錯誤
{
"error": {
"root_cause": [
{
"type": "class_cast_exception",
"reason": "java.lang.String cannot be cast to java.util.Map"
}
],
"type": "class_cast_exception",
"reason": "java.lang.String cannot be cast to java.util.Map"
},
"status": 500
}
實際上,語法從此改變了一點點。 您需要將查詢修改為:
{
"query": {
"constant_score" : {
"filter" : {
"exists" : { "field" : "name" }
}
}
},
"script" : {
"inline": "ctx._source.alias = ctx._source.name;"
}
}
ES 6更新
使用source
而不是inline
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.