# How to append a document without knowing it's id?

**URL:** <https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596>\
**Category:** Elasticsearch\
**Created:** [June 15, 2017, 4:39pm UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596 "2017-06-15T16:39:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [June 15, 2017, 4:39pm UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596/1 "2017-06-15T16:39:36Z")

</div>

What should I do if I don't know the id of the doc?

Here is my case:  
I have a nested doc like:  
{  
"Name" : "ABC",  
"Tag" : {  
"Tag1" : "DEF",  
"Tag2" : "GHI"  
}  
}

and another doc like:  
{  
"Name" : "XYZ",  
"Tag" : {  
"Tag1" : "DEF",  
"Tag2" : "GHI"  
}  
}

I want to append them since they have same Tag1 and Tag2 values.  
My final doc should be:  
{  
"Name" : "ABC", "XYZ"  
"Tag" : {  
"Tag1" : "DEF",  
"Tag2" : "GHI"  
}  
}

I do not have the ID of the docs.  
How to I append?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 15, 2017, 5:36pm UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596/2 "2017-06-15T17:36:03Z")

</div>

You can use [Update by Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) which allows applying an update to the resulting set of a search.

---

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [June 15, 2017, 9:09pm UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596/3 "2017-06-15T21:09:58Z")

</div>

How do I Update by Query using the Java API?  
Is it possible, since I cannot find the documentation under the Java API docs?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 16, 2017, 12:47am UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596/4 "2017-06-16T00:47:48Z")

</div>

Can you try using this [https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java](https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java) ?

---

<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 14, 2017, 12:47am UTC](https://discuss.elastic.co/t/how-to-append-a-document-without-knowing-its-id/89596/5 "2017-07-14T00:47:56Z")

</div>

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