# ScalaMapFieldExtractor Cannot extract value from entity

**URL:** <https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [June 7, 2017, 8:19am UTC](https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530 "2017-06-07T08:19:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonlucalandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonlucalandi/32/14990_2.png) [@simonlucalandi](https://discuss.elastic.co/u/simonlucalandi)\
**Post date:** [June 7, 2017, 8:19am UTC](https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530/1 "2017-06-07T08:19:51Z")

</div>

Hello there.  
I have an RDD[SubscriptionInfo] wher SubscriptionInfo is a defined as a case class .

I'm trying to save the rdd to ES and I want to specify the \_id to use, so I'm using something like this:

`rdd.saveToEs("spark/docs", Map("es.mapping.id" -> "sub_id"))`

but I get an error:

`Caused by: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: [ScalaMapFieldExtractor for field [[sub_id]]] cannot extract value from entity [class java.lang.String] | instance [Some(SubscriptionInfo(ea9db3d23862862e68886de79bd2d489_4307394759,None,Some(List(Billing(Sun May 07 00:03:06 UTC 2017,2.0,None))),None,None,2.0,EmptyLTV()))]`

Which is the correct way to specify the mapping id in this case?

---

<div class="post-metadata">

**Author:** ![simonlucalandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonlucalandi/32/14990_2.png) [@simonlucalandi](https://discuss.elastic.co/u/simonlucalandi)\
**Post date:** [June 7, 2017, 12:21pm UTC](https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530/2 "2017-06-07T12:21:31Z")

</div>

It seams that the solution is to use and additional map stage, as suggested in [https://discuss.elastic.co/t/cannot-extract-value-from-entity/66556](https://discuss.elastic.co/t/cannot-extract-value-from-entity/66556)

> rdd.map({case Some(subscriptionInfo) =\> subscriptionInfo}).saveToEs("spark/docs", Map("es.mapping.id" -\> "sub\_id"))

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [June 7, 2017, 2:04pm UTC](https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530/3 "2017-06-07T14:04:07Z")

</div>

My advice would be to avoid using Optional classes with ES-Hadoop since most of the logic is null aware already.

---

<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, 2:04pm UTC](https://discuss.elastic.co/t/scalamapfieldextractor-cannot-extract-value-from-entity/88530/4 "2017-07-05T14:04:13Z")

</div>

Closed on July 5, 2017, 2:04pm UTC

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