# Updating field value issue

**URL:** https://discuss.elastic.co/t/updating-field-value-issue/219896
**Category:** Elasticsearch
**Created:** [February 19, 2020, 4:57am UTC](https://discuss.elastic.co/t/updating-field-value-issue/219896 "2020-02-19T04:57:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Muhammad\_Ariful\_Isla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_ariful_isla/32/55732_2.png) [@Muhammad\_Ariful\_Isla](https://discuss.elastic.co/u/Muhammad_Ariful_Isla)
#### Post date: [February 19, 2020, 4:57am UTC](https://discuss.elastic.co/t/updating-field-value-issue/219896/1 "2020-02-19T04:57:24Z")

</div>

I am trying to work with `update_by_query` but cannot make it work.

Following is a simple query,

```auto
curl -X GET "172.17.0.3:9200/useripvsuserid/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "_source":"userid","query": {
    "term": {
      "userip": "10.0.30.181"
    }
  }
}
'
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 10.803431,
    "hits" : [
      {
        "_index" : "useripvsuserid",
        "_type" : "_doc",
        "_id" : "PhfBW3AB8mhGfmGvIs-j",
        "_score" : 10.803431,
        "_source" : {
          "userid" : "hasan1855"
        }
      }
    ]
  }
}

```

Following is the `update_by_query` that is not working. I am trying to replace `userid` value `hasan1855` to `arif`. Where is the problem?

```auto
curl -X POST "172.17.0.3:9200/useripvsuserid/_update_by_query?pretty" -H 'Content-Type: application/json' -d'
{
  "script": {                                                                                                                                                                                                        
    "source": "ctx._source.userid='arif';",
    "lang": "painless"       
  }, 
  "query": {
    "term": {
      "userip": "10.0.30.181"
    }
  }
}
'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "ctx._source.userid=arif;",
          " ^---- HERE"
        ],
        "script" : "ctx._source.userid=arif;",
        "lang" : "painless"
      }
    ],
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "ctx._source.userid=arif;",
      " ^---- HERE"
    ],
    "script" : "ctx._source.userid=arif;",
    "lang" : "painless",
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Variable [arif] is not defined."
    }
  },
  "status" : 400
}

```

---

<div class="post-metadata">

### Author: ![Muhammad\_Ariful\_Isla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_ariful_isla/32/55732_2.png) [@Muhammad\_Ariful\_Isla](https://discuss.elastic.co/u/Muhammad_Ariful_Isla)
#### Post date: [February 19, 2020, 7:17am UTC](https://discuss.elastic.co/t/updating-field-value-issue/219896/2 "2020-02-19T07:17:46Z")

</div>

Solved it by escaping quotes in `script` section like the following,

```auto
          "ctx._source.userid=\"arif\";",

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 18, 2020, 7:17am UTC](https://discuss.elastic.co/t/updating-field-value-issue/219896/3 "2020-03-18T07:17:49Z")

</div>

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