# Connection timeout when resthighlevel client is called from spark mapPartitions method

**URL:** <https://discuss.elastic.co/t/connection-timeout-when-resthighlevel-client-is-called-from-spark-mappartitions-method/301492>\
**Category:** Elasticsearch\
**Tags:** language-clients, es-hadoop\
**Created:** [April 4, 2022, 10:21am UTC](https://discuss.elastic.co/t/connection-timeout-when-resthighlevel-client-is-called-from-spark-mappartitions-method/301492 "2022-04-04T10:21:28Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![vinayak\_j](https://avatars.discourse-cdn.com/v4/letter/v/e47c2d/32.png) [@vinayak\_j](https://discuss.elastic.co/u/vinayak_j)\
**Post date:** [April 4, 2022, 1:19pm UTC](https://discuss.elastic.co/t/connection-timeout-when-resthighlevel-client-is-called-from-spark-mappartitions-method/301492/3 "2022-04-04T13:19:54Z")

</div>

Didnt used curl commands to test ; but have checked like if we do connection outside mapPartitions() and put sample request we get a response. If we do the same inside mapPartitions() it gives connection time out.

We use dataproc to submit spark ; since code in the driver gets response; when we do the same inside mapPartitions() it has to yield response.

Also we have referred this:

> [@Serializing Elasticsearch clients for use when looping through Spark RDDs](https://discuss.elastic.co/t/serializing-elasticsearch-clients-for-use-when-looping-through-spark-rdds/126164/4):
>
> Thanks! @james.baiera and @hokiegeek2 My apologies for cross posting. Please find below the current code that we have. I will try your suggestion for rewriting the code to use the rest client instead. Apologies in advance for a long list of exceptions. I am providing it as per @hokiegeek2's request for the current problem. The connection manager to Elasticsearch is as follows: object Connection { def conn() = { val port = 9300 val NodeName = "node1" val ESClusterName = "esclust…

Declaring RestHighLevelClient as private , would lead to serialization issue; so we declared it as transient.

---

_[View the full topic](https://discuss.elastic.co/t/connection-timeout-when-resthighlevel-client-is-called-from-spark-mappartitions-method/301492)._
