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.SourceFormatter1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver) at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver ) at Nest.ReadAsFormatter
2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Elasticsearch.Net.Utf8Json.Formatters.CollectionFormatterBase4.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, Nullable1 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