forked from elastic/elasticsearch-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use serializer when deserializing LazyDocument to T (elastic#2791)
* Use serializer when deserializing LazyDocument to T When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers. Fixes elastic#2788 * Direct cast * Add non-generic overload for As() Relates elastic#2408 (cherry picked from commit 109bcb0)
- Loading branch information
Showing
4 changed files
with
130 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Linq; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using FluentAssertions.Common; | ||
using Nest; | ||
using Tests.Framework; | ||
using Tests.Framework.ManagedElasticsearch.Clusters; | ||
using Xunit; | ||
|
||
namespace Tests.Reproduce | ||
{ | ||
public class GithubIssue2788 : IClusterFixture<WritableCluster> | ||
{ | ||
private readonly WritableCluster _cluster; | ||
|
||
public GithubIssue2788(WritableCluster cluster) | ||
{ | ||
_cluster = cluster; | ||
} | ||
|
||
// 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; } | ||
} | ||
|
||
[I] | ||
public void CanDeserializeNumberToTimeSpanInInnerHits() | ||
{ | ||
var indexName = "sample"; | ||
var client = _cluster.Client; | ||
|
||
//create index with automapping | ||
client.CreateIndex(indexName, create => create | ||
.Mappings(mappings => mappings | ||
.Map<Root>(map => map | ||
.AutoMap() | ||
) | ||
) | ||
); | ||
|
||
var startTime = new TimeSpan(1, 2, 3); | ||
var endTime = new TimeSpan(2, 3, 4); | ||
|
||
client.Index(new Root | ||
{ | ||
Children = new[] | ||
{ | ||
new Child | ||
{ | ||
StartTime = startTime, | ||
EndTime = endTime | ||
|
||
} | ||
} | ||
}, index => index | ||
.Index(indexName) | ||
.Refresh(Refresh.WaitFor) | ||
); | ||
|
||
var result = client.Search<Root>(search => search | ||
.Query(query => query | ||
.Nested(nested => nested | ||
.Query(nestedQuery => nestedQuery | ||
.MatchAll() | ||
) | ||
.Path(i => i.Children) | ||
.InnerHits() | ||
) | ||
) | ||
.Index(indexName) | ||
); | ||
|
||
var child = result.Hits.First().InnerHits.Single().Value.Documents<Child>().Single(); | ||
|
||
child.Should().NotBeNull(); | ||
child.StartTime.Should().Be(startTime); | ||
child.EndTime.Should().Be(endTime); | ||
} | ||
} | ||
} |