# NEST date deserialization challenges

**URL:** <https://discuss.elastic.co/t/nest-date-deserialization-challenges/198994>\
**Category:** Elasticsearch\
**Created:** [September 11, 2019, 2:49am UTC](https://discuss.elastic.co/t/nest-date-deserialization-challenges/198994 "2019-09-11T02:49:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpatrick00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpatrick00/32/53956_2.png) [@rpatrick00](https://discuss.elastic.co/u/rpatrick00)\
**Post date:** [September 11, 2019, 2:49am UTC](https://discuss.elastic.co/t/nest-date-deserialization-challenges/198994/1 "2019-09-11T02:49:52Z")

</div>

I have an Index in Elasticsearch 7.2.0 with mappings that look like the following:

> {  
> "settings": {  
> "analysis": {  
> "normalizer": {  
> "lowercase\_normalizer": {  
> "type": "custom",  
> "char\_filter": ,  
> "filter": ["lowercase"]  
> }  
> }  
> }  
> },  
> "mappings": {  
> "properties": {  
> "CustomerId": { "type": "keyword", "normalizer": "lowercase\_normalizer" },  
> "Person": {  
> "properties": {  
> "FirstName": { "type": "keyword", "normalizer": "lowercase\_normalizer" },  
> "MiddleName": { "type": "keyword", "normalizer": "lowercase\_normalizer", "index": false },  
> "LastName": { "type": "keyword", "normalizer": "lowercase\_normalizer" },  
> "DateOfBirth": { "type": "date", "format": "MM/dd/yyyy" }  
> }  
> },  
> "CurrentBalance": { "type": "scaled\_float", "scaling\_factor": 100, "index": false },  
> "DueDate": { "type": "date", "format": "MM/dd/yyyy", "index": false }  
> }  
> }  
> }

Using the python APIs, I am able to search the index using Person.DateOfBirth without any issues. Unfortunately, when I try to query the same index from C# using the Nest 7.2.0 client, I am running into issues that appear to be related to (de)serializing the dates from/to C# DateTime objects. The docs are confusing, at best, given the changes between 6.x and 7.0 with regards to NEST serialization.

> \<20:55:41 \<Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:\> \<An unhandled exception has occurred while executing the request. Elasticsearch.Net.UnexpectedElasticsearchClientException: invalid datetime format. value:08/05/1983 ---\> System.InvalidOperationException: invalid datetime format. value:08/05/1983  
> at Elasticsearch.Net.Utf8Json.Formatters.ISO8601DateTimeFormatter.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)  
> at Deserialize(Object , JsonReader& , IJsonFormatterResolver )  
> at Deserialize(Object , JsonReader& , IJsonFormatterResolver )  
> at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte bytes, Int32 offset, IJsonFormatterResolver resolver)  
> at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)  
> at Elasticsearch.Net.DiagnosticsSerializerProxy.Deserialize[T](Stream stream)  
> at Nest.SourceFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver) at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver ) at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)  
> at Elasticsearch.Net.Utf8Json.Formatters.CollectionFormatterBase`4.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver) at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver ) at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)  
> at Deserialize(Object , JsonReader& , IJsonFormatterResolver )  
> at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte bytes, Int32 offset, IJsonFormatterResolver resolver)  
> at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)  
> at Elasticsearch.Net.DiagnosticsSerializerProxy.Deserialize[T](Stream stream)  
> at Elasticsearch.Net.ResponseBuilder.SetBody[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType)  
> at Elasticsearch.Net.ResponseBuilder.ToResponse[TResponse](RequestData requestData, Exception ex, Nullable`1 statusCode, IEnumerable`1 warnings, Stream responseStream, String mimeType)
> 
> snip...

I tried adding/removing the [Date(Format = "MM/dd/yyyy"] attribute to my DateTime fields but the result is the same both ways. I can see in Fiddler that the underlying query to Elastic is working and returning the expected data but I cannot figure out how to get past this DateTime serialization issue.

What do I need to do in order to make NEST handle this properly?

Thanks,  
Robert

---

<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 9, 2019, 2:49am UTC](https://discuss.elastic.co/t/nest-date-deserialization-challenges/198994/2 "2019-10-09T02:49:53Z")

</div>

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