Update elastic search doc field value for specific fields in all documents

Helping

New Member
#1
I have documents like this.
Mã:
{
"a":"test",
"b":"harry"
},
{
"a":""
"b":"jack"
}
I need to update docs with field a==""(empty string) to default value say null in all documents for a given index. Any help is appreciated. Thanks
 

Admin

Administrator
Thành viên BQT
#2
Use Update by query with ingest

_update_by_query can also use the Ingest Node feature by specifying a pipeline like this:

define the pipeline

Mã:
PUT _ingest/pipeline/set-foo
{
  "description" : "sets foo",
  "processors" : [ {
      "set" : {
        "field": "a",
        "value": null
      }
  } ]
}
then you can use it like:
Mã:
POST myindex/_update_by_query?pipeline=set-foo
{
 "query": {
   "filtered": {
     "filter": {
       "script": {
         "script": "_source._content.length() == 0"
       }
     }
   }
 }
}'
OR
Mã:
    POST myindex/_update_by_query?pipeline=set-foo
    {
        "query": {
            "bool" : {
                "must" : {
                    "script" : {
                        "script" : {
                            "inline": "doc['a'].empty",
                            "lang": "painless"
                         }
                    }
                }
            }
        }
    }
 
Top