Skip to content

Commit

Permalink
Fix parsing of DateHistogramBucket key (#131)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Jan 30, 2023
1 parent f099fd4 commit c98cdc0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch.Client/Aggregations/AggregateFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(); // :
Expand Down
44 changes: 44 additions & 0 deletions tests/Tests.Reproduce/GitHubIssue130.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Parsing histogram interval failed: <a href="https://github.com/opensearch-project/opensearch-net/issues/130">Issue #130</a>
/// </summary>
///
public class GitHubIssue130 : IClusterFixture<WritableCluster>
{
private readonly WritableCluster _cluster;

public GitHubIssue130(WritableCluster cluster) => _cluster = cluster;

[I] public void CanDeserializeDateHistogramBucket()
{
var response = _cluster.Client.Search<Project>(c => c
.Size(0)
.Query(q => q.MatchAll())
.Aggregations(a => a.Histogram("aggregation_ranges", r => r
.Field(f => f.LastActivity)
.Interval(5000)
)
)
);

response.ShouldBeValid();
}
}
}

0 comments on commit c98cdc0

Please sign in to comment.