# Indexing child docs using bulk api

**URL:** <https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061>\
**Category:** Elasticsearch\
**Created:** [December 13, 2012, 5:12am UTC](https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061 "2012-12-13T05:12:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [December 13, 2012, 5:12am UTC](https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061/1 "2012-12-13T05:12:12Z")

</div>

Hi there,  
I need to reindex my data, and I am using the parent child  
relations in my index, and now i need to use the bulk api for reindexing  
the data. I studied the bulk api  
[http://www.elasticsearch.org/guide/reference/api/bulk.html](http://www.elasticsearch.org/guide/reference/api/bulk.html)

but I could not understand how can I index child doc using this api, as I  
need to provide the parent id with the request.

Please give some idea how to deal with it...

Thanks  
Narinder Kaur

--

---

<div class="post-metadata">

**Author:** ![Dan\_Lecocq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_lecocq/32/2565_2.png) [@Dan\_Lecocq](https://discuss.elastic.co/u/Dan_Lecocq)\
**Post date:** [December 13, 2012, 10:15pm UTC](https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061/2 "2012-12-13T22:15:44Z")

</div>

To clarify, you're not reindexing the parent documents? Is there any chance  
that you're setting the id as a function of the contents of the document?  
Or one of the fields?

On Wednesday, December 12, 2012 9:12:12 PM UTC-8, Narinder Kaur wrote:

> Hi there,  
> I need to reindex my data, and I am using the parent child  
> relations in my index, and now i need to use the bulk api for reindexing  
> the data. I studied the bulk api  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> 
> but I could not understand how can I index child doc using this api, as I  
> need to provide the parent id with the request.
> 
> Please give some idea how to deal with it...
> 
> Thanks  
> Narinder Kaur

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [December 13, 2012, 11:08pm UTC](https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061/3 "2012-12-13T23:08:50Z")

</div>

If you need to index child documents via the bulk api, you can just  
put the parent uid in the bulk index items. The child document bulk  
item should look like this:  
{ "index" : { "\_index" : "[index]", "\_type" : "[child-type]", "\_id" :  
"[uid]", "parent", "[parent-uid]" } } // index request for a child  
document  
{ "field1" : "value1" } // the actual document soure  
... // rest of bulk request. Also each line in the bulk request needs a newline.

When indexing the child document, you need to know to what parent it  
belongs to. So you need to fetch it from somewhere (your db / storage  
or ES).

Martijn

On 13 December 2012 23:15, Dan Lecocq [dan@seomoz.org](mailto:dan@seomoz.org) wrote:

> To clarify, you're not reindexing the parent documents? Is there any chance  
> that you're setting the id as a function of the contents of the document? Or  
> one of the fields?
> 
> On Wednesday, December 12, 2012 9:12:12 PM UTC-8, Narinder Kaur wrote:
> 
> > Hi there,  
> > I need to reindex my data, and I am using the parent child  
> > relations in my index, and now i need to use the bulk api for reindexing the  
> > data. I studied the bulk api  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/bulk.html)
> > 
> > but I could not understand how can I index child doc using this api, as I  
> > need to provide the parent id with the request.
> > 
> > Please give some idea how to deal with it...
> > 
> > Thanks  
> > Narinder Kaur
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<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, 2:59am UTC](https://discuss.elastic.co/t/indexing-child-docs-using-bulk-api/10061/4 "2017-07-06T02:59:53Z")

</div>


