How to update values present in particular field for every docs in index using DSL query

Hi,

I want to update a particular field in the index. Index contains 100 docs.
I want to update field "name" with "condition_system" in every doc where "Condition System" is present.

GET part_ther/_search
{
        "_index" : "part_ther",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "LMK" : 42.6,
          "Num" : 364482,
          "id" : 1849,
          "name" : "Condition System ",
         "Number" : "G1",

I got update method but it's updating single doc per request. Can I update field "name" in all docs in single request.

POST part_ther/_update/1
{
  "doc": {
            "LMK" : 42.6,
          "Num" : 364482,
          "id" : 1849,
          "name" : "condition_system",
         "Number" : "G1",
  }
}

Sadly it's only working on integers not on characters/strings, don't know.
This code is able to change numerical values but not characters.
intergers are getting updated successfullly.

POST /part/_update_by_query
{
  "script": {
    "source": "ctx._source.scheduled_program_id=8475",
    "lang": "painless"
  },
  "query": { 
    "term": {
      "scheduled_program_id": "8457"
    }
  }
} 
Output-
{
  "took" : 30,
  "timed_out" : false,
  "total" : 2,
  "updated" : 2,
  "deleted" : 0,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

Code for pat_ther, but it's not update condition_system like numerical data above.


POST /part_ther/_update_by_query
{
  "script": {
    "source": "ctx._source.device_type =condition_system",
    "lang": "painless"
  },
  "query": { 
    "term": {
      "device_type": "Condition System"
    }
  }
} 

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.