# Error Handling while Adding Data

**URL:** <https://discuss.elastic.co/t/error-handling-while-adding-data/211068>\
**Category:** Elasticsearch\
**Created:** [December 9, 2019, 8:28am UTC](https://discuss.elastic.co/t/error-handling-while-adding-data/211068 "2019-12-09T08:28:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayyappa\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayyappa_p/32/59015_2.png) [@Ayyappa\_P](https://discuss.elastic.co/u/Ayyappa_P)\
**Post date:** [December 9, 2019, 8:28am UTC](https://discuss.elastic.co/t/error-handling-while-adding-data/211068/1 "2019-12-09T08:28:40Z")

</div>

Hi,

I have created a entity definition with a date time field. And if I'm entering any other value than date time type, then that record is not getting added into elastic and it is throwing an error. But I'm getting success Index response, with httpstatus code 200. But in Debug Info it is showing as `errors:true` . I want to throw an error whenever I'm getting a response like this from Elastic side. How can I do it.

Please find my debug Info here.  
` { "took": 5, "errors": true, "items": [{ "index": { "_index": "RandomKey", "_type": "RandomKey", "_id": "RandomID", "status": 400, "error": { "type": "mapper_parsing_exception", "reason": "failed to parse [dtDateTime]", "caused_by": { "type": "illegal_argument_exception", "reason": "Invalid format: \"SOme Text for check\"" } } } } ] }`

Column dtDateTime is a datetime column and I'm sending some text in this. **I have added ThrowExceptions = true . but it is not throwing any Exception.**

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 9, 2019, 1:46pm UTC](https://discuss.elastic.co/t/error-handling-while-adding-data/211068/2 "2019-12-09T13:46:22Z")

</div>

if you do a bulk index operation, you cannot rely on the response of the HTTP request, but you have to check each response item `status` field, like in your example it shows a 400 error, meaning that the client apparently some invalid data.

---

<div class="post-metadata">

**Author:** ![Ayyappa\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayyappa_p/32/59015_2.png) [@Ayyappa\_P](https://discuss.elastic.co/u/Ayyappa_P)\
**Post date:** [December 10, 2019, 4:30am UTC](https://discuss.elastic.co/t/error-handling-while-adding-data/211068/3 "2019-12-10T04:30:07Z")

</div>

Thanks @spinscale, But is there any way I can access response items other than DebugInfo. Like any property of Response? or can we use the `ElasticsearchClientException` class? If we can use it, then can you give me an example in C#.

---

<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:** [January 7, 2020, 4:30am UTC](https://discuss.elastic.co/t/error-handling-while-adding-data/211068/4 "2020-01-07T04:30:22Z")

</div>

Closed on January 7, 2020, 4:30am UTC

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