diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b04c02550..91ff59ba89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Removed `net461` target from internal packages ([#128](https://github.com/opensearch-project/opensearch-net/pull/128)) ### Fixed +- Fixed parsing of date histogram buckets ([#131](https://github.com/opensearch-project/opensearch-net/pull/131)) ### Security - CVE-2019-0820: Removed transitive dependencies on `System.Text.RegularExpressions` from internal packages; **Client Not Impacted** ([#137](https://github.com/opensearch-project/opensearch-net/pull/137)) diff --git a/src/OpenSearch.Client/Aggregations/AggregateFormatter.cs b/src/OpenSearch.Client/Aggregations/AggregateFormatter.cs index 9216b29a56..59674986e7 100644 --- a/src/OpenSearch.Client/Aggregations/AggregateFormatter.cs +++ b/src/OpenSearch.Client/Aggregations/AggregateFormatter.cs @@ -843,7 +843,7 @@ private IBucket GetDateHistogramBucket(ref JsonReader reader, IJsonFormatterReso reader.ReadNext(); // , reader.ReadNext(); // "key" reader.ReadNext(); // : - var key = reader.ReadInt64(); + var key = reader.ReadDouble(); reader.ReadNext(); // , reader.ReadNext(); // "doc_count" reader.ReadNext(); // : diff --git a/tests/Tests.Reproduce/GitHubIssue130.cs b/tests/Tests.Reproduce/GitHubIssue130.cs new file mode 100644 index 0000000000..7f0236667c --- /dev/null +++ b/tests/Tests.Reproduce/GitHubIssue130.cs @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using System.Linq; +using System.Threading; +using OpenSearch.Client; +using OpenSearch.OpenSearch.Xunit.XunitPlumbing; +using Tests.Core.Extensions; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Domain; + +namespace Tests.Reproduce +{ + /// + /// Parsing histogram interval failed: Issue #130 + /// + /// + public class GitHubIssue130 : IClusterFixture + { + private readonly WritableCluster _cluster; + + public GitHubIssue130(WritableCluster cluster) => _cluster = cluster; + + [I] public void CanDeserializeDateHistogramBucket() + { + var response = _cluster.Client.Search(c => c + .Size(0) + .Query(q => q.MatchAll()) + .Aggregations(a => a.Histogram("aggregation_ranges", r => r + .Field(f => f.LastActivity) + .Interval(5000) + ) + ) + ); + + response.ShouldBeValid(); + } + } +}