# Spark import es join type

**URL:** <https://discuss.elastic.co/t/spark-import-es-join-type/177574>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [April 19, 2019, 7:03am UTC](https://discuss.elastic.co/t/spark-import-es-join-type/177574 "2019-04-19T07:03:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![001kulou](https://avatars.discourse-cdn.com/v4/letter/0/a5b964/32.png) [@001kulou](https://discuss.elastic.co/u/001kulou)\
**Post date:** [April 19, 2019, 7:03am UTC](https://discuss.elastic.co/t/spark-import-es-join-type/177574/1 "2019-04-19T07:03:28Z")

</div>

es6.X version URL：[https://cloud.tencent.com/developer/article/1106756](https://cloud.tencent.com/developer/article/1106756)  
This is a join type mapping  
"mappings":{  
"business1":{  
"properties":{  
"my\_join\_field":{  
"type":"join",  
"relations":{  
"company":[  
"shareholder",  
"mainmember" ]  
}}}}}

Import parent document to set my\_join\_field value to company

But importing a child document requires specifying the name of routing and my\_join\_field and the parent of the parent document.

For example：

1PUT my\_join\_index/\_doc/3?routing=1&refresh  
2{  
3 "text": "This is an answer",  
4 "my\_join\_field": {  
5 "name": "answer",  
6 "parent": "1"  
7 }

I want to use Scala to write import subdocument code，But when I write my\_join\_field, I don't know what to write.

My example：

```
var mp = Map("name"->"answer","parent"->"1")
        var js= Json(DefaultFormats).write(mp)
        val numbers = Map("my_join_field" -> js ,"companyKeyNoM" -> "123132321321", "companyNames" -> "甘肃伊仁工贸有限公司","Plaintiff"->"兰州银行股份有限公司兰园支行","Defendant"->"马占义","Court"->"甘肃省兰州市中级人民法院","Type"->"裁判文书","Content"->"马占义：本院受理原告兰州银行股份有限公司兰园支行诉甘肃伊仁工贸有限公司、临夏州鑫盛民族用品有限责任公司、丁乃比由、马孝仁、丁而乃、马占义、马福华、马小荣、马小文、马如海借款合同纠纷一案，现已审理终结。现依法向你们公告送达本院（2016）甘01民初147号民事判决书。限你自公告之日起60日内来本院民事审判第二庭领取该民事判决书，逾期则视为送达。如不服本判决，可在判决书送达之日起十五日内，向本院递交上诉状，并按照对方当事人的人数提出副本，上诉于甘肃省高级人民法院。","Date"->"2017-10-12")
        val mapRDD = sc.makeRDD(Seq(numbers))
        mapRDD.saveToEs("business-data1/business1")

```

but throw Exception:  
failed to parse;org.elasticsearch.hadoop.rest.EsHadoopRemoteException: illegal\_argument\_exception: unknown join name [{"name":"1231231","parent":"12313123"}] for field [my\_join\_field]

Please tell me how to write the value of this field in scala code when importing join type

Thanks！

---

<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:** [May 17, 2019, 7:03am UTC](https://discuss.elastic.co/t/spark-import-es-join-type/177574/2 "2019-05-17T07:03:43Z")

</div>

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