# Updating data fields

**URL:** <https://discuss.elastic.co/t/updating-data-fields/103769>\
**Category:** Elasticsearch\
**Created:** [October 12, 2017, 4:35pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769 "2017-10-12T16:35:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![afonso.ribeiro](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@afonso.ribeiro](https://discuss.elastic.co/u/afonso.ribeiro)\
**Post date:** [October 12, 2017, 4:35pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/1 "2017-10-12T16:35:39Z")

</div>

Hello guys,

I want to update a field in elasticsearch but with a condition. In sql it would like something like this:

- UPDATE table\_name  
SET column1 = value1  
WHERE column1="blabla" and column1="bleble";

Can I do this in elasticsearch?

I suppose it is something like this but with the condition:

POST test/type1/  
{  
"tags" : ["red"]  
}

Can you help me?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 12, 2017, 4:48pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/2 "2017-10-12T16:48:54Z")

</div>

Update by query is what you are looking for

---

<div class="post-metadata">

**Author:** ![afonso.ribeiro](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@afonso.ribeiro](https://discuss.elastic.co/u/afonso.ribeiro)\
**Post date:** [October 12, 2017, 5:05pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/3 "2017-10-12T17:05:20Z")

</div>

Something like this?

POST twitter/\_update\_by\_query?conflicts=proceed  
{  
"query": {  
"term": {  
"user": "kimchy"  
}  
}  
}

I can't fully understand what is being updated. What I can see here is that all the kimchy value in user field is going to be updated but to what?

Thanks for the help. And sorry if the questions are being very basic.

Best regards,  
Afonso Ribeiro

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 12, 2017, 5:35pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/4 "2017-10-12T17:35:27Z")

</div>

All segments in Elasticsearch are immutable, so there are no in-place updates. The full documents will therefore be reindexed.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 12, 2017, 5:45pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/5 "2017-10-12T17:45:28Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

> What I can see here is that all the kimchy value in user field is going to be updated but to what?

No. You are just selected here all documents which are matching `kimchy` on the `name` field. You are here just reindexing them without changing anything in the `_source`.  
This is used when you change the mapping and wants to add a sub field in the mapping. You have for that to reevaluate all the documents.

But you can add a script to transform the document:

```auto
  "script": {
    "source": "ctx._source.foo=1",
    "lang": "painless"
  },

```

Or define an ingest processor which will do the transformation:

```auto
PUT _ingest/pipeline/set-foo
{
  "description" : "sets foo",
  "processors" : [ {
      "set" : {
        "field": "foo",
        "value": "bar"
      }
  } ]
}
POST twitter/_update_by_query?pipeline=set-foo

```

---

<div class="post-metadata">

**Author:** ![afonso.ribeiro](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@afonso.ribeiro](https://discuss.elastic.co/u/afonso.ribeiro)\
**Post date:** [October 13, 2017, 1:36pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/6 "2017-10-13T13:36:26Z")

</div>

Ok. I will take a look at that.

Thank you very much

---

<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:** [November 10, 2017, 1:36pm UTC](https://discuss.elastic.co/t/updating-data-fields/103769/7 "2017-11-10T13:36:28Z")

</div>

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