elasticsearch批量更新文档的某个字段

版本为ES 5.2 

POST index/type/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "if (ctx._source.abc== null) {ctx._source.abc= 0}"
  }
}

abc是某字段;

当es中数据量非常巨大时,一次请求不能完全执行成功,会出现超时(默认1分钟),此时采用带有搜索条件的批量操作,如下:

POST  index/type/_update_by_query
{
  "script": {
    "inline": "ctx._source.actionTime='20181008104853';ctx._source.createTime='20181008104853'"
  },
  "query": {
    "range": {
      "productID": {
        "gte": 0,
        "lte": 10000
      }
    }
  }
}

POST  index/type/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "if(ctx._source.test== null){ctx._source.test= 0}  if(ctx._source.ab== null){ctx._source.ab= 1}"
  }
}

 

你可能感兴趣的:(elasticsearch,elasticsearch)