# Spark sql insert json dataframe into elastic search

**URL:** <https://discuss.elastic.co/t/spark-sql-insert-json-dataframe-into-elastic-search/93795>\
**Category:** Elasticsearch\
**Created:** [July 19, 2017, 3:04pm UTC](https://discuss.elastic.co/t/spark-sql-insert-json-dataframe-into-elastic-search/93795 "2017-07-19T15:04:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mackindo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mackindo/32/20246_2.png) [@mackindo](https://discuss.elastic.co/u/mackindo)\
**Post date:** [July 19, 2017, 3:04pm UTC](https://discuss.elastic.co/t/spark-sql-insert-json-dataframe-into-elastic-search/93795/1 "2017-07-19T15:04:05Z")

</div>

I've looked at the guide section for using spark SQL dataframe/dataset to insert json data into elastic search, but the section "Writing existing JSON to ElasticSearch" tells you to use sql load method, which gets data FROM elasticsearch to populate a dataframe in spark.

Link to section I am referring to:  
[https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-sql-json](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-sql-json)

I have spark log data and load that into a spark dataframe. I want to use elastic search spark library to bulk load that into elastic search. The closest I can get so far is pre aggregating the json data myself using spark and running dataframe.saveToEs("spark/.logs").

If I have val df = sqlContext.read.json("hdfs path")  
I should be able to use the json schema as it has been worked out already.

What json save to Es method can I use?

Thanks,  
Alistair

---

<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 16, 2017, 3:04pm UTC](https://discuss.elastic.co/t/spark-sql-insert-json-dataframe-into-elastic-search/93795/2 "2017-08-16T15:04:07Z")

</div>

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