# Catch EsHadoopSerializationException while saving from spark

**URL:** <https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [November 23, 2016, 6:11pm UTC](https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024 "2016-11-23T18:11:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sushant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sushant/32/13374_2.png) [@sushant](https://discuss.elastic.co/u/sushant)\
**Post date:** [November 23, 2016, 6:11pm UTC](https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024/1 "2016-11-23T18:11:13Z")

</div>

Hi,

I'm currently trying to load some data into elastic search. I'm using the following snippet to write to ES

```
// input here is an rdd of json string
EsSpark.saveJsonToEs(input, "offers/product", Map[String, String]("es.mapping.id" -> "lumi_name"))

```

There seems to be some data strings which cause the job to fail

```
6/11/21 15:21:27 ERROR Executor: Exception in task 5021.3 in stage 1.0 (TID 42312)
org.elasticsearch.hadoop.serialization.EsHadoopSerializationException: org.codehaus.jackson.JsonParseException: Unexpected character ('h' (code 104)): was expecting comma to separate OBJECT entries
at [Source: [B@1a1d6f03; line: 1, column: 20]
at org.elasticsearch.hadoop.serialization.json.JacksonJsonParser.nextToken(JacksonJsonParser.java:95)
at org.elasticsearch.hadoop.serialization.ParsingUtils.doFind(ParsingUtils.java:167)
at org.elasticsearch.hadoop.serialization.ParsingUtils.values(ParsingUtils.java:150)
at org.elasticsearch.hadoop.serialization.field.JsonFieldExtractors.process(JsonFieldExtractors.java:201)
at org.elasticsearch.hadoop.serialization.bulk.JsonTemplatedBulk.preProcess(JsonTemplatedBulk.java:64)
at org.elasticsearch.hadoop.serialization.bulk.TemplatedBulk.write(TemplatedBulk.java:54)
at org.elasticsearch.hadoop.rest.RestRepository.writeToIndex(RestRepository.java:158)

```

Is there a way I can catch this error while writing to ES, so that the job doesn't fail but I can gracefully handle bad data?

Thanks,  
Sushant

---

<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:** [November 28, 2016, 4:35pm UTC](https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024/2 "2016-11-28T16:35:20Z")

</div>

@sushant Right now the connector does not provide any failure hooks for bad data. I would instead recommend preemptively checking and remediating the JSON before it is sent out to the connector.

---

<div class="post-metadata">

**Author:** ![sushant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sushant/32/13374_2.png) [@sushant](https://discuss.elastic.co/u/sushant)\
**Post date:** [November 29, 2016, 3:50am UTC](https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024/3 "2016-11-29T03:50:10Z")

</div>

@james.baiera Thanks for the clarification.

---

<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:** [December 27, 2016, 3:50am UTC](https://discuss.elastic.co/t/catch-eshadoopserializationexception-while-saving-from-spark/67024/4 "2016-12-27T03:50:53Z")

</div>

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