# Data gets deleted on update by query when the \_source field is set on the body

**URL:** <https://discuss.elastic.co/t/data-gets-deleted-on-update-by-query-when-the--source-field-is-set-on-the-body/86627>\
**Category:** Elasticsearch\
**Created:** [May 22, 2017, 8:47am UTC](https://discuss.elastic.co/t/data-gets-deleted-on-update-by-query-when-the--source-field-is-set-on-the-body/86627 "2017-05-22T08:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibreta](https://avatars.discourse-cdn.com/v4/letter/i/e95f7d/32.png) [@ibreta](https://discuss.elastic.co/u/ibreta)\
**Post date:** [May 22, 2017, 8:47am UTC](https://discuss.elastic.co/t/data-gets-deleted-on-update-by-query-when-the--source-field-is-set-on-the-body/86627/1 "2017-05-22T08:47:53Z")

</div>

Hello,

I ran into an interesting case upon executing an update\_by\_query instruction.  
First, I've executed the instruction with only the query field. As it is specified in the documentation, nothing happens with the data. The operation reports updates, but the matched documents aren't really updated as there is no statement demanding that.  
Afterwards, I've added a \_source field on the request body. After executing the query, I was a bit surprised to find out that the matched documents got deleted.

My question is: is this the expected behavior? I've read the docs, but I couldn't find out any clues on what should happen when using the \_source field on an update\_by\_query.  
For the \_update instruction, the \_source field behaves the same way as it behaves on the \_search instruction.

Thank you in advance,  
Ionut

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 26, 2017, 7:40am UTC](https://discuss.elastic.co/t/data-gets-deleted-on-update-by-query-when-the--source-field-is-set-on-the-body/86627/2 "2017-05-26T07:40:05Z")

</div>

Hi @ibreta

Update by query consists of a scrolled search request with bulk updates, so the `_source` parameter is passed to scrolled search and determines what part of the source document is returned. If you set it to `false`, then update by query will throw an exception saying (eg) `[myindex][mytype][1] didn't store _source` . If you set it to something else (like a list of field names), then only those field names will be present in the new documents.

---

<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:** [June 23, 2017, 7:40am UTC](https://discuss.elastic.co/t/data-gets-deleted-on-update-by-query-when-the--source-field-is-set-on-the-body/86627/3 "2017-06-23T07:40:20Z")

</div>

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