# How to update documents based on query?

**URL:** <https://discuss.elastic.co/t/how-to-update-documents-based-on-query/2371>\
**Category:** Elasticsearch\
**Created:** [June 10, 2015, 6:32pm UTC](https://discuss.elastic.co/t/how-to-update-documents-based-on-query/2371 "2015-06-10T18:32:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nadja](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@Nadja](https://discuss.elastic.co/u/Nadja)\
**Post date:** [June 10, 2015, 6:32pm UTC](https://discuss.elastic.co/t/how-to-update-documents-based-on-query/2371/1 "2015-06-10T18:32:11Z")

</div>

Hi,

I'm stuck at following

I need to run partial update on documents, which would match following query:

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"field1": "test"  
}  
},  
{  
"missing": {  
"field": "field2"  
}  
}  
]  
}  
}  
}  
}  
}

I could write java program, which would first retrieve this documents, and run another query to update the field in them.

in sql it would  
update table  
set field='updated'  
where field1 = 'value' and field2 is null;

Is there any simpler way to do it?

---

<div class="post-metadata">

**Author:** ![Maarten\_Roosendaal](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Maarten\_Roosendaal](https://discuss.elastic.co/u/Maarten_Roosendaal)\
**Post date:** [June 10, 2015, 6:39pm UTC](https://discuss.elastic.co/t/how-to-update-documents-based-on-query/2371/2 "2015-06-10T18:39:38Z")

</div>

Hi,

There's some good documentation out there, this one should help:  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html)

Cheers,  
Maarten

---

<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 6, 2017, 12:08am UTC](https://discuss.elastic.co/t/how-to-update-documents-based-on-query/2371/3 "2017-07-06T00:08:30Z")

</div>


