# Query then update documents by using scripting

**URL:** <https://discuss.elastic.co/t/query-then-update-documents-by-using-scripting/8914>\
**Category:** Elasticsearch\
**Created:** [September 2, 2012, 3:38pm UTC](https://discuss.elastic.co/t/query-then-update-documents-by-using-scripting/8914 "2012-09-02T15:38:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawn](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shawn](https://discuss.elastic.co/u/shawn)\
**Post date:** [September 2, 2012, 3:38pm UTC](https://discuss.elastic.co/t/query-then-update-documents-by-using-scripting/8914/1 "2012-09-02T15:38:04Z")

</div>

Hi fellows,

Is there a way to do query first then update specific field of the  
documents returned on server side? I found there are scripting tutorials on  
querying and updating documents respectively, but there is nothing on  
combining these two together.

Thanks in advance

Shawn

--

---

<div class="post-metadata">

**Author:** ![Radu\_Gheorghe1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe1/32/2688_2.png) [@Radu\_Gheorghe1](https://discuss.elastic.co/u/Radu_Gheorghe1)\
**Post date:** [September 3, 2012, 7:00am UTC](https://discuss.elastic.co/t/query-then-update-documents-by-using-scripting/8914/2 "2012-09-03T07:00:43Z")

</div>

Hi Shawn,

One way to do it is from your application. For example, do a query, take  
the results, change them to whatever you want, then update them. If you  
have too many results, you might need to do a scroll on your search results.

On Sunday, September 2, 2012 6:38:04 PM UTC+3, shawn wrote:

> Hi fellows,
> 
> Is there a way to do query first then update specific field of the  
> documents returned on server side? I found there are scripting tutorials on  
> querying and updating documents respectively, but there is nothing on  
> combining these two together.
> 
> Thanks in advance
> 
> Shawn

--

---

<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, 3:14am UTC](https://discuss.elastic.co/t/query-then-update-documents-by-using-scripting/8914/3 "2017-07-06T03:14:17Z")

</div>


