# Connection Spark and ElasticSearch

**URL:** <https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [July 23, 2017, 6:21pm UTC](https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251 "2017-07-23T18:21:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SG87](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@SG87](https://discuss.elastic.co/u/SG87)\
**Post date:** [July 23, 2017, 6:21pm UTC](https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251/1 "2017-07-23T18:21:32Z")

</div>

Hi,

I am using Python SQL Spark 2.1.0 and ElasticSearch 5.5.0 and I am trying to use the following command:  
`df.write.format("es").save("db/test")`

My configuration options are as follows:  
`$SPARK_HOME/bin/pyspark --packages org.elasticsearch:elasticsearch-spark-20_2.11:5.3.1 --conf spark.es.nodes="52.XXX.XX.XX" --conf spark.es.port="9201" --conf spark.es.nodes.discovery=true --conf spark.es.net.http.auth.user="user" --conf spark.es.net.http.auth.pass="Password" --conf spark.es.nodes.wan.only=true`

(I tried both with spark.es.nodes.wan.only=true and spark.es.nodes.wan.only=false

Before with an elastic 2.4.5 cluster, this was working perfectly fine, Now I am receive the following error:  
An error occurred while calling o50.save.  
: org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: [HEAD] on [db/test] failed; server[52.XXX.XX.XX:9201] returned [400|Bad Request:]  
at org.elasticsearch.hadoop.rest.RestClient.checkResponse(RestClient.java:505)  
at org.elasticsearch.hadoop.rest.RestClient.executeNotFoundAllowed(RestClient.java:476)  
at org.elasticsearch.hadoop.rest.RestClient.exists(RestClient.java:537)  
at org.elasticsearch.hadoop.rest.RestRepository.isEmpty(RestRepository.java:473)  
at org.elasticsearch.spark.sql.ElasticsearchRelation.isEmpty(DefaultSource.scala:508)  
at org.elasticsearch.spark.sql.DefaultSource.createRelation(DefaultSource.scala:96)  
at org.apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:518)  
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:215)  
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:198)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)  
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)  
at py4j.Gateway.invoke(Gateway.java:280)  
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)  
at py4j.commands.CallCommand.execute(CallCommand.java:79)  
at py4j.GatewayConnection.run(GatewayConnection.java:214)  
at java.lang.Thread.run(Thread.java:745)

I als tried to connect using a private and/or public key, with the following configuration settings:  
`--conf spark.es.net.ssl.keystore.location="/Users/stijngeuens/.ssh/key" --conf spark.es.net.ssl=true`

In this case I received the following error:  
An error occurred while calling o51.save.  
: org.elasticsearch.hadoop.rest.EsHadoopTransportException: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

Could anybody help on this matter?

---

<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:** [July 24, 2017, 3:10pm UTC](https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251/2 "2017-07-24T15:10:11Z")

</div>

Try upgrading to ES-Hadoop 5.5.0. In 5.5.0, Elasticsearch removed an old deprecated endpoint for checking existence on types. This was fixed in the ES-Hadoop 5.5.0 release.

---

<div class="post-metadata">

**Author:** ![SG87](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@SG87](https://discuss.elastic.co/u/SG87)\
**Post date:** [July 30, 2017, 8:10am UTC](https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251/3 "2017-07-30T08:10:17Z")

</div>

Thanks. I am able to conncet.

---

<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:** [August 27, 2017, 8:10am UTC](https://discuss.elastic.co/t/connection-spark-and-elasticsearch/94251/4 "2017-08-27T08:10:45Z")

</div>

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