# Calling esRDD in a transformation method causes Task not serializable

**URL:** <https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [January 26, 2016, 1:52am UTC](https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078 "2016-01-26T01:52:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyunam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kyunam/32/3576_2.png) [@kyunam](https://discuss.elastic.co/u/kyunam)\
**Post date:** [January 26, 2016, 1:52am UTC](https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078/1 "2016-01-26T01:52:36Z")

</div>

Is the following not allowed because nested RDD is prohibited?

```auto
val computedRDD = anRDD.map {
    ...
    val anotherRDD = sc.esRDD(...)
   ...
}

```

Thanks,  
Q

---

<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:** [January 27, 2016, 8:38pm UTC](https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078/2 "2016-01-27T20:38:12Z")

</div>

As I've mentioned in another [thread](https://discuss.elastic.co/t/esrdd-not-returning-script-fields-values/40077/2), you are being quite cryptic in your questions so it's hard to understand what the issue is.

Task not serializable it's a common issue in Spark cause by the fact that you are passing around code which is not serializable. And yes, nesting an `RDD` of any kind qualify as such - take a look into the Spark docs, it's easy to get around it by keeping the data point outside your code and trying to leverage as much as possible the `RDD` functions.  
Note that an `RDD` is a distributed collection in the end - it acts like one but it's actually a proxy to a distributed job.

---

<div class="post-metadata">

**Author:** ![kyunam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kyunam/32/3576_2.png) [@kyunam](https://discuss.elastic.co/u/kyunam)\
**Post date:** [January 29, 2016, 6:11pm UTC](https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078/3 "2016-01-29T18:11:43Z")

</div>

That was a silly newbie question from me.  
Now I know/learned from your response and further [google searches](https://groups.google.com/forum/#!topic/spark-users/rkVPXAiCiBk) that creating another RDD or calling actions inside a transformation is disallowed.

Thanks again,  
-Q

---

<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:** [January 29, 2016, 9:12pm UTC](https://discuss.elastic.co/t/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078/4 "2016-01-29T21:12:12Z")

</div>

No worries. Everyone starts as a newbie.

---

<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/calling-esrdd-in-a-transformation-method-causes-task-not-serializable/40078/5 "2017-07-06T13:26:17Z")

</div>


