# How to APPEND new data in index against id using spark scala

**URL:** https://discuss.elastic.co/t/how-to-append-new-data-in-index-against-id-using-spark-scala/101308
**Category:** Elasticsearch
**Tags:** es-hadoop
**Created:** [September 21, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-append-new-data-in-index-against-id-using-spark-scala/101308 "2017-09-21T10:15:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Akshay\_60](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Akshay\_60](https://discuss.elastic.co/u/Akshay_60)
#### Post date: [September 21, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-append-new-data-in-index-against-id-using-spark-scala/101308/1 "2017-09-21T10:15:14Z")

</div>

Hi ,

I am working on spark for processing and after processing I am ingesting data into ES.But issue is that whenever I am running that code it is updating that but I want every time data should be appended.

**I have used "index" option ...**

val conf:SparkConf = new SparkConf().setAppName("spark session example").setMaster("local").set("es.index.auto.create","true").set("es.nodes","nodes").st("es.port","9200").set("es.http.timeout","1m").set("[es.mapping.id](http://es.mapping.id)","session\_id").set("es.write.operation","index")

**I also have used "upsert" option ..**

val conf:SparkConf = new SparkConf().setAppName("spark session example").setMaster("local").set("es.index.auto.create","true").set("es.nodes","nodes").st("es.port","9200").set("es.http.timeout","1m").set("[es.mapping.id](http://es.mapping.id)","session\_id").set("es.write.operation","upsert")

\*\*My Requirement : \*\*

**Suppose first time , Ingested data would be like this**

"\_source": {  
"session\_id": "111",  
"ga\_section": [  
"abc",  
"abc",  
"def"  
]  
}

Now when I run again that code ...then new data should be appended like this  
((Suppose I have "abc","abc" against the same id ))

"\_source": {  
"session\_id": "111",  
"ga\_section": [  
"abc",  
"abc",  
"def",  
"abc",  
"abc"  
]  
}

---

<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: [October 19, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-append-new-data-in-index-against-id-using-spark-scala/101308/2 "2017-10-19T10:15:45Z")

</div>

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