Elasticsearch之Update

2018-06-04  本文已影响0人  DONG999

Painless script可以用来更新或新增field到一个document中, 下面是范例代码:

带参数更新

POST v2_tmm/doc/6SGjpWMBOloH49RB8o2r/_update
 {
   "script": {
     "lang": "painless",
     "source": "ctx._source.vid=333; ctx._source.first=params.first",
     "params": {
       "first": "aln",
       "last": "zhou"
     }
   }
   
 }

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

更新查询后的记录:

POST base_data/_update_by_query
{
  "script": {
    "source": "ctx._source.userid='updateduser'",
    "lang": "painless"
  },
  "query": {
        "match" : {
            "userid" : ""
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读