es update_by_query和delete_by_query

1. _update_by_query

(1)将 father 字段更新为 空数组


post paopao/info/_update_by_query
{
     "script": {
     "source": "ctx._source['father']=[]" 
  },
     "query": {
         "bool": {
          "must": [
               {
            "exists": {
            "field": "father"
          }
        }
      ]
    }
  }
}

注意,我这里是数组,若是字符串注意带上双引号

(2)将name字段和 age字段更新为指定值

post paopao/info/_update_by_query
{
   "script": {
        "inline": "ctx._source.name = params.name;ctx._source.age = params.age",
        "params": {
            "name": "paopao",
            "age":111111
        },
        "lang":"painless"
    },
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "age"
          }
        }
      ]
    }
  }
}

 

2. _delete_by_query

根据搜索出来的条件删除数据。如:清空数据库

post paopao/info/_delete_by_query
{
    "query":{
        "match_all":{}
    }
}

 

posted @ 2019-05-09 18:42  小跑跑泡  阅读(8777)  评论(0编辑  收藏  举报