# I am trying to change the values of the fields while querying the data to Vega

**URL:** <https://discuss.elastic.co/t/i-am-trying-to-change-the-values-of-the-fields-while-querying-the-data-to-vega/277995>\
**Category:** Elasticsearch\
**Tags:** vega\
**Created:** [July 6, 2021, 8:34pm UTC](https://discuss.elastic.co/t/i-am-trying-to-change-the-values-of-the-fields-while-querying-the-data-to-vega/277995 "2021-07-06T20:34:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aswanth\_jabba](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@aswanth\_jabba](https://discuss.elastic.co/u/aswanth_jabba)\
**Post date:** [July 6, 2021, 8:34pm UTC](https://discuss.elastic.co/t/i-am-trying-to-change-the-values-of-the-fields-while-querying-the-data-to-vega/277995/1 "2021-07-06T20:34:29Z")

</div>

So, I have data something like this

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/c/ec8c86126398ddee3edfc588a9e13f5cdec60004.png)

And I want the Data to be like :  
Except for **Closed** and **Submitted** _states_ it should change the value to **In Progress**

I know how this can be achieved through the scripted fields, but not sure where I should be using the scripted fields while pushing the data to Vega

Script Looks something like this :

```auto
if ((doc['state'].value != 'Closed') || (doc['state'].value != 'Submitted'))
{
return 'In Progress';
}

```

Please suggest anything what I should be doing in such case.

---

<div class="post-metadata">

**Author:** ![aswanth\_jabba](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@aswanth\_jabba](https://discuss.elastic.co/u/aswanth_jabba)\
**Post date:** [July 7, 2021, 12:47pm UTC](https://discuss.elastic.co/t/i-am-trying-to-change-the-values-of-the-fields-while-querying-the-data-to-vega/277995/2 "2021-07-07T12:47:01Z")

</div>

I got the issue solved by using the scripted fields in body, here is a sample

```auto
"data": [
    {
      "name": "source",
      "url": {
        "%context%": true,
        "%timefield%": "created",
        "index": "2.0.0-sampl-oper*",
        "body": {
          "size": 24,
          "_source": ["workitem", "state"],
          "script_fields": {
            "state": {
              "script": {
                "lang": "painless",
                "source": "if(doc['state'].value=='Closed')return 'Closed';if(doc['state'].value=='Submitted')return 'Not Started';else return 'In Progess';"
              }
            }
          }
        }
      },
      "format": {"property": "hits.hits"}
    }
]

```

But we cannot return the direct values of field itself and it should be a one line script.

---

<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:** [August 4, 2021, 12:47pm UTC](https://discuss.elastic.co/t/i-am-trying-to-change-the-values-of-the-fields-while-querying-the-data-to-vega/277995/3 "2021-08-04T12:47:47Z")

</div>

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