# Saving DF to Elasticsearch usig python

**URL:** <https://discuss.elastic.co/t/saving-df-to-elasticsearch-usig-python/75796>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [February 20, 2017, 10:01pm UTC](https://discuss.elastic.co/t/saving-df-to-elasticsearch-usig-python/75796 "2017-02-20T22:01:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![easyoups](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@easyoups](https://discuss.elastic.co/u/easyoups)\
**Post date:** [February 20, 2017, 10:01pm UTC](https://discuss.elastic.co/t/saving-df-to-elasticsearch-usig-python/75796/1 "2017-02-20T22:01:15Z")

</div>

Hi

I try to desesperately write a dataframe to Elasticsearch...  
I tried many differently config but I didn't find the right one.

Reading works fine :

```
[root@client ~]# cat test1.py
## imports

from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext

## constants
APP_NAME="test"

if __name__ == " __main__":

  conf = SparkConf()
  conf.set("es.nodes", "10.120.0.218:9200")

  sc = SparkContext(conf=conf)
  sqlContext = SQLContext(sc)

  df = sqlContext.read\
  .option("es.resource", "test/member")\
  .format("org.elasticsearch.spark.sql")\
  .load()
  df.show()

  sc.stop()

```

`[root@client ~]# /usr/hdp/2.5.3.0-37/spark/bin/spark-submit --master yarn --deploy-mode cluster --jars hdfs:/spark-libs/elasticsearch-hadoop-5.2.1.jar --num-executors 1 --executor-cores 4 --executor-memory 32G --verbose test1.py`

and output is :

```
Log Type: stdout
Log Upload Time: Mon Feb 20 21:46:12 +0000 2017
Log Length: 106
+------+-----------+
|abo_id| nickname|
+------+-----------+
| 123|supertomato|
+------+-----------+ 

```

... and trying to rewrite the df in the same index/type :

```
[root@client ~]# cat test1.py
## imports

from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext

## constants
APP_NAME="test"

if __name__ == " __main__":

  conf = SparkConf()
  conf.set("es.nodes", "10.120.0.218:9200")

  sc = SparkContext(conf=conf)
  sqlContext = SQLContext(sc)

  df = sqlContext.read\
  .option("es.resource", "test/member")\
  .format("org.elasticsearch.spark.sql")\
  .load()
  df.show()

  df.write\
    .format("org.elasticsearch.spark.sql")\
    .mode('append')\
    .option("spark.es.resource","test/member")\
    .save()

  sc.stop()

```

fails with error :

```
Traceback (most recent call last):
  File "test1.py", line 28, in <module>
    .option("spark.es.resource","test/member")\
  File "/hadoop/yarn/local/usercache/root/appcache/application_1486137522197_0190/container_e05_1486137522197_0190_01_000001/pyspark.zip/pyspark/sql/readwriter.py", line 395, in save
  File "/hadoop/yarn/local/usercache/root/appcache/application_1486137522197_0190/container_e05_1486137522197_0190_01_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 813, in __call__
  File "/hadoop/yarn/local/usercache/root/appcache/application_1486137522197_0190/container_e05_1486137522197_0190_01_000001/pyspark.zip/pyspark/sql/utils.py", line 45, in deco
  File "/hadoop/yarn/local/usercache/root/appcache/application_1486137522197_0190/container_e05_1486137522197_0190_01_000001/py4j-0.9-src.zip/py4j/protocol.py", line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o57.save.
: java.lang.AbstractMethodError: org.elasticsearch.spark.sql.DefaultSource.createRelation(Lorg/apache/spark/sql/SQLContext;Lorg/apache/spark/sql/SaveMode;Lscala/collection/immutable/Map;Lorg/apache/spark/sql/DataFrame;)Lorg/apache/spark/sql/sources/BaseRelation;
	at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:222)
	at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
	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:231)
	at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
	at py4j.Gateway.invoke(Gateway.java:259)
	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
	at py4j.commands.CallCommand.execute(CallCommand.java:79)
	at py4j.GatewayConnection.run(GatewayConnection.java:209)
	at java.lang.Thread.run(Thread.java:745)

```

Any idea ? Thx in advance...

---

<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:** [March 11, 2017, 7:30pm UTC](https://discuss.elastic.co/t/saving-df-to-elasticsearch-usig-python/75796/2 "2017-03-11T19:30:11Z")

</div>

@easyoups This looks familiar to [this issue](https://github.com/elastic/elasticsearch-hadoop/issues/852). Could you see if that solves your problem?

---

<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:** [April 8, 2017, 7:30pm UTC](https://discuss.elastic.co/t/saving-df-to-elasticsearch-usig-python/75796/3 "2017-04-08T19:30:28Z")

</div>

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