# How to read/write to Elasticsearch with Apache Spark with scala

**URL:** <https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703>\
**Category:** Elasticsearch\
**Created:** [October 30, 2018, 5:53pm UTC](https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703 "2018-10-30T17:53:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_5amy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_5amy/32/32662_2.png) [@m\_5amy](https://discuss.elastic.co/u/m_5amy)\
**Post date:** [October 30, 2018, 5:53pm UTC](https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703/1 "2018-10-30T17:53:23Z")

</div>

How to read/write to Elasticsearch with Apache Spark with scala

Elasticsearch version 5  
Spark version 2.2  
Any Help ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 30, 2018, 8:59pm UTC](https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703/2 "2018-10-30T20:59:05Z")

</div>

What have you tried?

---

<div class="post-metadata">

**Author:** ![m\_5amy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_5amy/32/32662_2.png) [@m\_5amy](https://discuss.elastic.co/u/m_5amy)\
**Post date:** [October 31, 2018, 11:50am UTC](https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703/3 "2018-10-31T11:50:01Z")

</div>

i'm trying to write and read to elasticsearch using apache spark  
but data written to elasticsearch in format base64

this is the code i'm using to write to elasticsearch

```auto
var df = spark.readStream
        .format("kafka")
        .option("kafka.bootstrap.servers", KafkaService.bootstrapServers)
        .option("enable.auto.commit", KafkaService.enableAutoCommit)
        .option("failOnDataLoss", KafkaService.failOnDataLoss)
        .option("startingOffsets", KafkaService.startingOffsets)
        .option("subscribe", topicName)
        .option("group.id", groupId)
        .load()
    
    df.writeStream
    .outputMode(OutputMode.Append) //Only mode for ES
    .format("org.elasticsearch.spark.sql") //es
    .queryName("ElasticSink" + topicName)
    .start(indexName + "/broadcast") //ES index

```

---

<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:** [November 28, 2018, 11:50am UTC](https://discuss.elastic.co/t/how-to-read-write-to-elasticsearch-with-apache-spark-with-scala/154703/4 "2018-11-28T11:50:04Z")

</div>

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