|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Text; |
| 7 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
| 8 | +using Elasticsearch.Net; |
| 9 | +using FluentAssertions; |
| 10 | +using Nest; |
| 11 | + |
| 12 | +namespace Tests.Reproduce |
| 13 | +{ |
| 14 | + public class GitHubIssue4333 |
| 15 | + { |
| 16 | + [U] |
| 17 | + public void CanDeserializeYearIntervalUnit() |
| 18 | + { |
| 19 | + var json = @"{ |
| 20 | + ""took"" : 162, |
| 21 | + ""timed_out"" : false, |
| 22 | + ""_shards"" : { |
| 23 | + ""total"" : 3, |
| 24 | + ""successful"" : 3, |
| 25 | + ""skipped"" : 0, |
| 26 | + ""failed"" : 0 |
| 27 | + }, |
| 28 | + ""hits"" : { |
| 29 | + ""total"" : 4089559, |
| 30 | + ""max_score"" : 0.0, |
| 31 | + ""hits"" : [ ] |
| 32 | + }, |
| 33 | + ""aggregations"" : { |
| 34 | + ""modDate"" : { |
| 35 | + ""buckets"" : [ |
| 36 | + { |
| 37 | + ""key_as_string"" : ""2013-01-01T00:00:00.000Z"", |
| 38 | + ""key"" : 1356998400000, |
| 39 | + ""doc_count"" : 32 |
| 40 | + }, |
| 41 | + { |
| 42 | + ""key_as_string"" : ""2014-01-01T00:00:00.000Z"", |
| 43 | + ""key"" : 1388534400000, |
| 44 | + ""doc_count"" : 617 |
| 45 | + }, |
| 46 | + { |
| 47 | + ""key_as_string"" : ""2015-01-01T00:00:00.000Z"", |
| 48 | + ""key"" : 1420070400000, |
| 49 | + ""doc_count"" : 183 |
| 50 | + }, |
| 51 | + { |
| 52 | + ""key_as_string"" : ""2016-01-01T00:00:00.000Z"", |
| 53 | + ""key"" : 1451606400000, |
| 54 | + ""doc_count"" : 3479 |
| 55 | + }, |
| 56 | + { |
| 57 | + ""key_as_string"" : ""2017-01-01T00:00:00.000Z"", |
| 58 | + ""key"" : 1483228800000, |
| 59 | + ""doc_count"" : 1948427 |
| 60 | + }, |
| 61 | + { |
| 62 | + ""key_as_string"" : ""2018-01-01T00:00:00.000Z"", |
| 63 | + ""key"" : 1514764800000, |
| 64 | + ""doc_count"" : 555748 |
| 65 | + }, |
| 66 | + { |
| 67 | + ""key_as_string"" : ""2019-01-01T00:00:00.000Z"", |
| 68 | + ""key"" : 1546300800000, |
| 69 | + ""doc_count"" : 1268034 |
| 70 | + }, |
| 71 | + { |
| 72 | + ""key_as_string"" : ""2020-01-01T00:00:00.000Z"", |
| 73 | + ""key"" : 1577836800000, |
| 74 | + ""doc_count"" : 313039 |
| 75 | + } |
| 76 | + ], |
| 77 | + ""interval"" : ""1y"" |
| 78 | + } |
| 79 | + } |
| 80 | + }"; |
| 81 | + |
| 82 | + var bytes = Encoding.UTF8.GetBytes(json); |
| 83 | + var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); |
| 84 | + var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(bytes)).DefaultIndex("default_index"); |
| 85 | + var client = new ElasticClient(connectionSettings); |
| 86 | + |
| 87 | + var response = client.Search<object>(); |
| 88 | + |
| 89 | + Func<AutoDateHistogramAggregate> func = () => response.Aggregations.AutoDateHistogram("modDate"); |
| 90 | + |
| 91 | + var agg = func.Should().NotThrow().Subject; |
| 92 | + agg.Interval.Should().Be("1y"); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments