how to using append first string update by query elasticsearch

Viewed 18

i have doc:

{
  "_index" : "name_index",
  "_type" : "_doc",
  "_id" : "45db3736bcccb55f28b9162b20d0c3",
  "_score" : 1.0,
  "_source" : {
    "path" : {
      "virtual" : "/2014/01/01/filename.pdf"
    }
  }
}

how to append a string to first path.virtual: "virtual" : "Uploads/2014/01/01/filename.pdf"

1 Answers

If you want to update all document of your index (or a sub-set thereof), you can do it with _update_by_query coupled with an ingest pipeline. First, define your ingest pipeline:

PUT _ingest/pipeline/modify-path
{
  "processors": [
    {
      "set": {
        "field": "path.virtual",
        "value": "Uploads{{{path.virtual}}}"
      }
    }
  ]
}

And then run it over your index, like this:

POST name_index/_update_by_query?pipeline=modify-path
{
     "query": {
          "match_all": {}
     }
}

If you want to do it just over that one document, you can do it with a normal update like this:

POST name_index/_doc/45db3736bcccb55f28b9162b20d0c3/_update
{
  "doc": {
    "path": {
       "virtual": "Uploads/2014/01/01/filename.pdf"
    }
  }
}
Related