# Reindex parent-child documents using elasticsearch.helpers paralel\_bulk

**URL:** <https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585>\
**Category:** Elasticsearch\
**Created:** [October 21, 2016, 8:36am UTC](https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585 "2016-10-21T08:36:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moshe\_Sucaz](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@Moshe\_Sucaz](https://discuss.elastic.co/u/Moshe_Sucaz)\
**Post date:** [October 21, 2016, 8:36am UTC](https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585/1 "2016-10-21T08:36:26Z")

</div>

Hi,  
I wrote my own script to re-index our docs from elastic 1.5.2 to 2.3.4 using the elasticsearch.helpers  
paralel\_bulk.  
My question is: Will paralel\_bulk re-index children documents with “parent=” ? Because when debugging it, I didn't see “parent” in the returned doc.  
My script is:

> def parallel\_reindex(index\_name, doc\_type, chunk\_size=500, scroll='10m', scan\_kwargs={}, bulk\_kwargs={}):  
> target\_client = Elasticsearch(hosts=['target\_host:9200'], retry\_on\_timeout=True, max\_retries=10, timeout=1000)  
> source\_client = Elasticsearch(hosts=['source\_host:9200'], retry\_on\_timeout=True, max\_retries=10, timeout=1000)  
> query = {"query": {"match\_all": {}}}  
> docs = scan(source\_client,  
> query = query,  
> index = index\_name,  
> scroll = scroll,  
> doc\_type=doc\_type,  
> \*\* scan\_kwargs  
> )  
> def _change\_doc\_params\_to\_elastic\_2(hits):  
> for h in hits:  
> # change field with “.” to “_”  
> if 'x.y.z' in h['\_source']:  
> h['\_source']['x\_y\_z'] = h['\_source']['x.y.z']  
> del h['\_source']['x.y.z']  
> # removing \_analyzer  
> if '\_analyzer' in h['\_source']:  
> del h['\_source']['\_analyzer']  
> if 'fields' in h:  
> h.update(h.pop('fields'))  
> yield h  
> kwargs = {  
> 'stats\_only': True,  
> }  
> kwargs.update(bulk\_kwargs)  
> for response in parallel\_bulk(target\_client, \_change\_doc\_params\_to\_elastic\_2(docs), thread\_count=8, chunk\_size=chunk\_size):  
> pass  
> # reindex\_log.info("responce: ", response)

> pool = ThreadPool(3)  
> for doc\_type in ["a",”b”,”c”]: #b and c are children's of a  
> pool.add\_task(parallel\_reindex, index\_name, doc\_type)  
> reindex\_log.info("waiting for all child docs to finish\n")  
> pool.wait\_completion()

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 21, 2016, 9:05am UTC](https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585/2 "2016-10-21T09:05:15Z")

</div>

In 1.x the \_parent field isn't included by default in responses.  
You need to ask for it explicitly in your requests.

---

<div class="post-metadata">

**Author:** ![Moshe\_Sucaz](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@Moshe\_Sucaz](https://discuss.elastic.co/u/Moshe_Sucaz)\
**Post date:** [October 21, 2016, 9:25am UTC](https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585/3 "2016-10-21T09:25:29Z")

</div>

Thanks Mark!  
I will do that...

---

<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 5, 2017, 10:10pm UTC](https://discuss.elastic.co/t/reindex-parent-child-documents-using-elasticsearch-helpers-paralel-bulk/63585/4 "2017-07-05T22:10:37Z")

</div>


