# Use saveJsonToEs and always keep the same \_id field

**URL:** <https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [March 11, 2016, 4:04pm UTC](https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178 "2016-03-11T16:04:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_Journel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophe_journel/32/12534_2.png) [@Christophe\_Journel](https://discuss.elastic.co/u/Christophe_Journel)\
**Post date:** [March 11, 2016, 4:04pm UTC](https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178/1 "2016-03-11T16:04:35Z")

</div>

Hello,

I would like to know whether there's a workaround to this issue with log parsing:

Before the 2.X version of Elasticsearch, i used this scala feature:  
`rdd.saveJsonToEs(indexAndType)` with JSON, containing an \_id field.

And my ES mapping contained the \_id field as a string.

This field was created with SHA256 from a log line. Therefore each log line could be in ES, and if want to reindex all data, the new line created a "version 2" of the document \_id.

Now, with 2.X \_id feature, i cannot use saveJsonToEs, because i am not allowed to use \_id in a JSON document.

I noticed that with bulk feature, i can add an \_id field:

```
[root@server ~]# cat all.json
{"index": {"_index": "testindex", "_type": "typeblabla", "_id": "uniq1-o"}}
{ "text": "toto" }
{"index": {"_index": "testindex", "_type": "typeblabla", "_id": "uniq1-a"}}
{ "text": "tata" }
{"index": {"_index": "testindex", "_type": "typeblabla", "_id": "uniq1-i"}}
{ "text": "titi" }

```

However, in scala, i just have a file with a huge number of json line:

```
{ "text": "toto", "_id":"uniq1"}
{ "text": "tata", "_id":"uniq2" }
{ "text": "titi", "_id":"uniq3" }
{ "text": "tutu", "_id":"uniq4" } 
[...]

```

How can i insert these data into ES and be sure that, if i reindex all data, they will have always the same \_id ?

Thanks.

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [March 12, 2016, 2:32pm UTC](https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178/2 "2016-03-12T14:32:31Z")

</div>

You should be able to achieve the same result by using `saveToEsWithMeta` which accepts key/values (key metadata, value the doc) and by setting `es.input.json` to true.  
If the key is determined from the doc, you can do so by setting an extractor.

---

<div class="post-metadata">

**Author:** ![Christophe\_Journel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophe_journel/32/12534_2.png) [@Christophe\_Journel](https://discuss.elastic.co/u/Christophe_Journel)\
**Post date:** [March 14, 2016, 10:51am UTC](https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178/3 "2016-03-14T10:51:13Z")

</div>

thanks for your help, i'll try this 🙂  
i'll post here the results of these tests.

---

<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:** [July 6, 2017, 1:25pm UTC](https://discuss.elastic.co/t/use-savejsontoes-and-always-keep-the-same--id-field/44178/4 "2017-07-06T13:25:45Z")

</div>


