在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

painless 部分更新nested字段

Elasticsearch | 作者 ReveeWu | 发布于2018年10月23日 | 阅读数:4937

有个nested字段需要批量部分更新,但是不知道painless该怎么写,求大神指教
 
 POST usercenter/cust/_update_by_query?conflicts=proceed
{
  "query": {
    "match_all":{}
  },
  "script":{
    "lang":"painless",
    "inline":"ctx['_source'].nestedfield.field=1"
  }
}
 
 
mapping:
 
{
  "usercenter-v1": {
    "mappings": {
      "cust": {
        "_all": {
          "enabled": false
        },
        "properties": {
          "bd_user_app": {
            "type": "nested",
            "properties": {
              "field": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}
已邀请:

rochy - rochy_he

赞同来自:

你可以参考下面的脚本进行部分更新
{
"script" : {
"source": "ctx['_source'].nestedfield[0].field = 1",
"lang": "painless"
}
}

要回复问题请先登录注册