Elasticsearch _update_by_query (二)

接上用script update by query

按条件更新

POST book/_update_by_query
{"script": {
  "lang": "painless",
  "source": """
  ctx._source.numb="2"
  """
  },
  "query": {
    "term": {
      "keyword": {
        "value": "oracle"
      }
    }
  }
}

按ID更新,重命名字段numb为text_entry 

POST book/_update/2
{
  "script": {
    "lang": "painless",
    "source": """
    String numb = ctx._source.numb;
    ctx._source.remove('numb');
    ctx._source.text_entry = numb;
    """
  }
}

全部文档增加字段commet

POST book/_update_by_query
{"script": {
  "lang": "painless",
  "source": """
  ctx._source.commet="welcome to commets"
  """
  },
  "query": {
   "match_all": {}
  }
}

删除条件

POST book/_delete_by_query
{
  "query":{
    "bool": {
      "should":{
        "term":{"keyword.keyword": "oracle"}
      }
    }
  }
}

 

posted on 2021-11-15 19:07  InnoLeo  阅读(202)  评论(0编辑  收藏  举报