Skip to content

AutoDateHistogramAggregate Interval should be DateMathTime #4725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Nest/Aggregations/AggregateFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ private IAggregate GetMultiBucketAggregate(ref JsonReader reader, IJsonFormatter
reader.ReadNext();
propertyName = reader.ReadPropertyNameSegmentRaw();
if (propertyName.EqualsBytes(JsonWriter.GetEncodedPropertyNameWithoutQuotation("interval")))
bucket.Interval = formatterResolver.GetFormatter<Time>().Deserialize(ref reader, formatterResolver);
bucket.Interval = formatterResolver.GetFormatter<DateMathTime>().Deserialize(ref reader, formatterResolver);
else
// skip for now
reader.ReadNextBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
{
public class AutoDateHistogramAggregate : MultiBucketAggregate<DateHistogramBucket>
{
public Time Interval { get; internal set; }
public DateMathTime Interval { get; internal set; }
}
}
2 changes: 1 addition & 1 deletion src/Nest/Aggregations/Bucket/BucketAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public class BucketAggregate : IAggregate
public IReadOnlyCollection<IBucket> Items { get; set; } = EmptyReadOnly<IBucket>.Collection;
public IReadOnlyDictionary<string, object> Meta { get; set; } = EmptyReadOnly<string, object>.Dictionary;
public long? SumOtherDocCount { get; set; }
public Time Interval { get; set; }
public DateMathTime Interval { get; set; }
}
}
95 changes: 95 additions & 0 deletions tests/Tests.Reproduce/GitHubIssue4333.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Text;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;

namespace Tests.Reproduce
{
public class GitHubIssue4333
{
[U]
public void CanDeserializeYearIntervalUnit()
{
var json = @"{
""took"" : 162,
""timed_out"" : false,
""_shards"" : {
""total"" : 3,
""successful"" : 3,
""skipped"" : 0,
""failed"" : 0
},
""hits"" : {
""total"" : 4089559,
""max_score"" : 0.0,
""hits"" : [ ]
},
""aggregations"" : {
""modDate"" : {
""buckets"" : [
{
""key_as_string"" : ""2013-01-01T00:00:00.000Z"",
""key"" : 1356998400000,
""doc_count"" : 32
},
{
""key_as_string"" : ""2014-01-01T00:00:00.000Z"",
""key"" : 1388534400000,
""doc_count"" : 617
},
{
""key_as_string"" : ""2015-01-01T00:00:00.000Z"",
""key"" : 1420070400000,
""doc_count"" : 183
},
{
""key_as_string"" : ""2016-01-01T00:00:00.000Z"",
""key"" : 1451606400000,
""doc_count"" : 3479
},
{
""key_as_string"" : ""2017-01-01T00:00:00.000Z"",
""key"" : 1483228800000,
""doc_count"" : 1948427
},
{
""key_as_string"" : ""2018-01-01T00:00:00.000Z"",
""key"" : 1514764800000,
""doc_count"" : 555748
},
{
""key_as_string"" : ""2019-01-01T00:00:00.000Z"",
""key"" : 1546300800000,
""doc_count"" : 1268034
},
{
""key_as_string"" : ""2020-01-01T00:00:00.000Z"",
""key"" : 1577836800000,
""doc_count"" : 313039
}
],
""interval"" : ""1y""
}
}
}";

var bytes = Encoding.UTF8.GetBytes(json);
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(bytes)).DefaultIndex("default_index");
var client = new ElasticClient(connectionSettings);

var response = client.Search<object>();

Func<AutoDateHistogramAggregate> func = () => response.Aggregations.AutoDateHistogram("modDate");

var agg = func.Should().NotThrow().Subject;
agg.Interval.Should().Be("1y");
}
}
}