# Insert parent doc and child doc in One Spark job

**URL:** <https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [February 14, 2016, 1:29pm UTC](https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718 "2016-02-14T13:29:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Netanel\_Malka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/netanel_malka/32/47520_2.png) [@Netanel\_Malka](https://discuss.elastic.co/u/Netanel_Malka)\
**Post date:** [February 14, 2016, 1:29pm UTC](https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718/1 "2016-02-14T13:29:33Z")

</div>

Hi,  
I try to insert parent doc to specific type, and child doc to another type in the same spark job.  
I defined in the spark conf the es.mapping.parent to the correct field.  
But when the job tries to saveJsonToEs(\<INDEX/TYPE\_NAME\>) , I got this exception:  
Caused by: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException:[JsonExtractor for field [parent]] cannot extract value from entity [class java.lang.String]

Thank's,

---

<div class="post-metadata">

**Author:** ![Netanel\_Malka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/netanel_malka/32/47520_2.png) [@Netanel\_Malka](https://discuss.elastic.co/u/Netanel_Malka)\
**Post date:** [February 14, 2016, 1:53pm UTC](https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718/2 "2016-02-14T13:53:36Z")

</div>

I found the solution:  
In the saveJsonToEs(\<INDEX\_NAME/TYPE\_NAME\>, Map("es.mapping.parent" -\> \<NAME\_OF\_PARENT\_FILED\> ))  
Instead of, defining it in the conf object of spark.

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [February 21, 2016, 10:39pm UTC](https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718/3 "2016-02-21T22:39:27Z")

</div>

Both configurations should work - what version of ES-Hadoop are you using and how do you define the `es.mapping.parent` "in the conf object of spark." ?

---

<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, 1:26pm UTC](https://discuss.elastic.co/t/insert-parent-doc-and-child-doc-in-one-spark-job/41718/4 "2017-07-06T13:26:07Z")

</div>


