# Update partial document by query

**URL:** https://discuss.elastic.co/t/update-partial-document-by-query/67962
**Category:** Elasticsearch
**Created:** [December 4, 2016, 10:17pm UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962 "2016-12-04T22:17:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![arno-london](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arno-london](https://discuss.elastic.co/u/arno-london)
#### Post date: [December 4, 2016, 10:17pm UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/1 "2016-12-04T22:17:26Z")

</div>

Hello,

I would like to update a partial document by query using Elasticsearch 2.4.  
I don't want to use the scripts tag because I don't want to enumerate all the fields, I would like to use a doc property like the simple update method. However it's not possible to write this part of the following code:  
doc: **MY\_PARTIAL\_DOC** ,

So the following code doesn't work:  
client.updateByQuery(  
{  
index: **MY\_INDEX** ,  
type: **MY\_TYPE** ,  
body: {  
query: {  
**MY\_QUERY**  
},  
doc: **MY\_PARTIAL\_DOC** ,  
}  
},  
MY\_CALLBACK  
);

Is there a solution? I have a workaround at the moment but I would like to update my document by query using only one request. Thanks.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 5, 2016, 9:14am UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/2 "2016-12-05T09:14:33Z")

</div>

Hey,

I am not sure what you mean by `scripts tag` here? Can you elaborate?

you can use the [reindex API with scripting](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/docs-reindex.html) which might cover your use-case?

--Alex

---

<div class="post-metadata">

### Author: ![arno-london](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arno-london](https://discuss.elastic.co/u/arno-london)
#### Post date: [December 5, 2016, 9:35am UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/3 "2016-12-05T09:35:03Z")

</div>

Hey,

Thank you for replying.  
Indeed, it's not the "script tag" but the "script property" of the updateByQuery API. For example:

```
"script": {
  "inline": "ctx._source.likes++",
  "lang": "painless"
}

```

Instead of this script property I'd like to use a doc property, like the one for the update API because I want to update most of the properties of a document. But this property doesn't exist for the updateByQuery API.

I'm happy to use any other API. However, for the reindex API, the Elasticsearch documentation says "Just like \_update\_by\_query, \_reindex gets a snapshot of the source index but its target must be a different index so version conflicts are unlikely". So I don't think this API is suitable for my needs since I don't want to change the index. I would like to update the document as a partial one.

Thanks.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 5, 2016, 10:32am UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/4 "2016-12-05T10:32:22Z")

</div>

Hey,

ah I see. I think then it makes most sense to use a scroll search and create bulk requests that use the update API.

--Alex

---

<div class="post-metadata">

### Author: ![arno-london](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arno-london](https://discuss.elastic.co/u/arno-london)
#### Post date: [December 5, 2016, 11:01am UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/5 "2016-12-05T11:01:54Z")

</div>

Thanks again for replying.

It's what I would have liked to avoid. Because I want to update only one document each time. For now I'm doing that, but I would have prefered to process only one update instead of a get and then an update. Even if I know an update is not only an update under the hood.

I'd like to use Elasticsearch as a datastore and not only as a search engine. I understand this kind of feature is not really necessary for a search engine. I don't have to do many updates, so getting the data before updating them is acceptable.

Thanks anyway for your help.

---

<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: [January 2, 2017, 11:01am UTC](https://discuss.elastic.co/t/update-partial-document-by-query/67962/6 "2017-01-02T11:01:59Z")

</div>

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