# saveToEsWithMeta with Json values

**URL:** <https://discuss.elastic.co/t/savetoeswithmeta-with-json-values/50655>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [May 22, 2016, 7:19pm UTC](https://discuss.elastic.co/t/savetoeswithmeta-with-json-values/50655 "2016-05-22T19:19:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadavsr](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@nadavsr](https://discuss.elastic.co/u/nadavsr)\
**Post date:** [May 22, 2016, 7:19pm UTC](https://discuss.elastic.co/t/savetoeswithmeta-with-json-values/50655/1 "2016-05-22T19:19:50Z")

</div>

I have my values already formatted as strings, but I can't use saveJsonToES since I want to pass in meta.

My code is like this:

```
val cfg: Map[String, String] = Map(
  ES_INPUT_JSON -> true.toString
)

def metaMap(id: String, version: Long): Map[Metadata, String] = Map(
  Metadata.ID -> id,
  Metadata.VERSION -> version.toString,
  Metadata.VERSION_TYPE -> "external")

 myRdd.map(v => (metaMap(v.id, v.version), v.jsonString)
    .writeToESWithMeta(resource, cfg)

```

I am getting this exception:

```
Caused by: org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: JsonParseException[Unexpected character ('d' (code 100)): was expecting comma to separate OBJECT entries
 at [Source: [B@768a0173; line: 1, column: 24]]; fragment[{"_id":813751de68ef4]

```

Maybe hadoop-es tries to interpret both the key and value as Json?

---

<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:** [May 24, 2016, 9:53am UTC](https://discuss.elastic.co/t/savetoeswithmeta-with-json-values/50655/2 "2016-05-24T09:53:31Z")

</div>

I'm not sure I follow.

If I understand the issue correctly, you are trying to save metadata while setting the `input` as JSON. The metadata itself is not in JSON format hence why you are getting the errors.  
You either let ES-Hadoop use its extractors (which can understand if the input is JSON or not) or handle everything by yourself - namely in this case properly escape the key as a JSON string with quotes.

---

<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:24pm UTC](https://discuss.elastic.co/t/savetoeswithmeta-with-json-values/50655/3 "2017-07-06T13:24:37Z")

</div>


