# (apache spark df).saveToES(elastic search)

**URL:** <https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [February 11, 2017, 3:16pm UTC](https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765 "2017-02-11T15:16:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muthu\_Jayakumar](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Muthu\_Jayakumar](https://discuss.elastic.co/u/Muthu_Jayakumar)\
**Post date:** [February 11, 2017, 3:16pm UTC](https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765/1 "2017-02-11T15:16:23Z")

</div>

Hello there,

I am new to elastic-search + apache-spark combination. I have a question on how I would be able to set datatypes in ElasticSearch for a dataframe I would be saving?  
For example, when I take a dataframe to save, some columns gets saved as 'text' type. I would like them to be saved as 'keyword' type. Also, would I be able to update the mappings before the dataframe is written into index or it can only be done after an write operation?

Please advice,  
Muthu

---

<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:** [February 14, 2017, 8:49pm UTC](https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765/2 "2017-02-14T20:49:27Z")

</div>

@Muthu_Jayakumar ES-Hadoop defers to Elasticsearch for automatically mapping fields. This means that string data is going to be automatically set to `text`, dates will also be set to `text` types, and so on.

If these mappings are not what you expect, then you must create the index and mappings on your own before sending documents with ES-Hadoop/Spark. Another simple way to handle this if you are working with multiple indices is to use [index templates](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html#delete) in Elasticsearch.

---

<div class="post-metadata">

**Author:** ![Muthu\_Jayakumar](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Muthu\_Jayakumar](https://discuss.elastic.co/u/Muthu_Jayakumar)\
**Post date:** [February 26, 2017, 4:43pm UTC](https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765/3 "2017-02-26T16:43:21Z")

</div>

Thanks for the note James. The index templates trick should work for me.

---

<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:** [March 26, 2017, 4:43pm UTC](https://discuss.elastic.co/t/apache-spark-df-savetoes-elastic-search/74765/4 "2017-03-26T16:43:37Z")

</div>

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