# Update document with another document/index

**URL:** <https://discuss.elastic.co/t/update-document-with-another-document-index/171714>\
**Category:** Elasticsearch\
**Created:** [March 11, 2019, 9:32am UTC](https://discuss.elastic.co/t/update-document-with-another-document-index/171714 "2019-03-11T09:32:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andurif](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@andurif](https://discuss.elastic.co/u/andurif)\
**Post date:** [March 11, 2019, 9:32am UTC](https://discuss.elastic.co/t/update-document-with-another-document-index/171714/1 "2019-03-11T09:32:52Z")

</div>

Hello,

I try to update some documents of my index with the update\_by\_query API and adding a new field. I manage to do that manually for one document with the script option.

For example:  
POST /my\_index/\_update\_by\_query  
{  
"script": {  
"source": "ctx.\_source.user = 'User XXX '",  
"lang": "painless"  
},  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"userid": 5  
}  
}  
],  
"must\_not": [  
{  
"exists" : {  
"field" : "user"  
}  
}  
]  
}  
}  
}`

My problem is that the information I want to put in the new field named user, is in another index or in another document.  
Is there any possibility to do that automatically for all documents ?

Thanks.

---

<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:** [March 11, 2019, 11:19am UTC](https://discuss.elastic.co/t/update-document-with-another-document-index/171714/2 "2019-03-11T11:19:52Z")

</div>

No. You can't do that automatically. You need to manage that manually.

---

<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:** [April 8, 2019, 11:19am UTC](https://discuss.elastic.co/t/update-document-with-another-document-index/171714/3 "2019-04-08T11:19:53Z")

</div>

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