# Please assist me to understand how Update By Query works to update source data

**URL:** <https://discuss.elastic.co/t/please-assist-me-to-understand-how-update-by-query-works-to-update-source-data/135822>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 3:01am UTC](https://discuss.elastic.co/t/please-assist-me-to-understand-how-update-by-query-works-to-update-source-data/135822 "2018-06-14T03:01:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechGeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/techgeek/32/28158_2.png) [@TechGeek](https://discuss.elastic.co/u/TechGeek)\
**Post date:** [June 14, 2018, 3:01am UTC](https://discuss.elastic.co/t/please-assist-me-to-understand-how-update-by-query-works-to-update-source-data/135822/1 "2018-06-14T03:01:39Z")

</div>

**Problem Statement** :- Using \_update\_by\_query not able to update the data at the source of index.

I have index with a name "poc" carries below data. I want to update the Color White with Red. To do so I am using following code to do

-Cond. 1.  
So far updating documents successfully without changing their source via below code.

> POST /poc/\_update\_by\_query?q=Color:White  
> {  
> "query":{  
> "term":{  
> "Color": "Red"  
> }  
> }  
> }

- Cond 2.

Using below code couldn't able to update the source data.

> POST poc/\_update\_by\_query  
> {  
> "script": {  
> "source": "ctx.\_source.Color = 'Red'",  
> "lang": "painless"  
> },  
> "query": {  
> "term":{  
> "Color": "White"  
> }  
> }  
> }

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

---

<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:** [July 12, 2018, 3:13am UTC](https://discuss.elastic.co/t/please-assist-me-to-understand-how-update-by-query-works-to-update-source-data/135822/2 "2018-07-12T03:13:22Z")

</div>

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