Closed
Description
NEST/Elasticsearch.Net version: 5.4.0
Elasticsearch version: 5.4.0
Description of the problem including expected versus actual behavior: Unable to deserialize number
field into TimeSpan
for inner hits. An attempt to deserialize inner hits into object leads to an exception: Newtonsoft.Json.JsonSerializationException: Error converting value 37230000000 to type 'System.TimeSpan'. Path 'startTime'.
Steps to reproduce:
// sample mapping with nested objects with TimeSpan field
class Root
{
[Nested]
public Child[] Children { get; set; }
}
class Child
{
public TimeSpan StartTime { get; set; }
public TimeSpan EndTime { get; set; }
}
var indexName = "sample";
var client = new ElasticClient(new ConnectionSettings().DefaultIndex(indexName));
//create index with automapping
client.CreateIndex(indexName, create => create.Mappings(mappings => mappings.Map<Root>(map => map.AutoMap())));
// add sample document
client.Index(new Root
{
Children = new[]
{
new Child
{
StartTime = new TimeSpan(1, 2, 3),
EndTime = new TimeSpan(2, 3, 4)
}
}
}, index => index.Refresh(Refresh.WaitFor));
// search with inner hits
var result = client.Search<Root>(
search => search.Query(
query => query.Nested(
nested => nested.Query(
nestedQuery => nestedQuery.MatchAll()
).Path(i => i.Children).InnerHits()
)
)
);
// try to deserialize (exception)
var children = result.Hits.First().InnerHits.Single().Value.Documents<Child>();
Metadata
Metadata
Assignees
Labels
No labels