Skip to content
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
28 changes: 23 additions & 5 deletions src/Nest/Aggregations/AggregateFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ ref ArraySegment<byte> propertyName
items.Add(item);
}

token = reader.GetCurrentJsonToken();
if (token == JsonToken.ValueSeparator)
{
reader.ReadNext();
propertyName = reader.ReadPropertyNameSegmentRaw();
if (propertyName.EqualsBytes(JsonWriter.GetEncodedPropertyNameWithoutQuotation("interval")))
bucket.Interval = formatterResolver.GetFormatter<Time>().Deserialize(ref reader, formatterResolver);
else
// skip for now
reader.ReadNextBlock();
}

bucket.Items = items;
reader.ReadNext(); // close outer }
return bucket;
Expand Down Expand Up @@ -745,15 +757,21 @@ private IBucket GetDateHistogramBucket(ref JsonReader reader, IJsonFormatterReso
reader.ReadNext(); // ,
reader.ReadNext(); // "key"
reader.ReadNext(); // :
var key = reader.ReadNullableLong().GetValueOrDefault(0);
var key = reader.ReadInt64();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact of porting over from Json.NET, where the conversion is made to long? - I don't believe nullability it's actually needed here, based on

https://github.com/elastic/elasticsearch/blob/daa2ec8a605d385a65b9ab3e89d016b3fd0dffe2/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogram.java#L114-L116

reader.ReadNext(); // ,
reader.ReadNext(); // "doc_count"
reader.ReadNext(); // :
var docCount = reader.ReadNullableLong().GetValueOrDefault(0);
reader.ReadNext(); // ,
var docCount = reader.ReadInt64();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, no longer nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to previous comment, this is an artifact of porting over from Json.NET. Based on

https://github.com/elastic/elasticsearch/blob/daa2ec8a605d385a65b9ab3e89d016b3fd0dffe2/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogram.java#L119-L121

there is always a long value for doc count.


var propertyName = reader.ReadPropertyName();
var subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver);
Dictionary<string, IAggregate> subAggregates = null;
if (reader.GetCurrentJsonToken() == JsonToken.ValueSeparator)
{
reader.ReadNext(); // ,
var propertyName = reader.ReadPropertyName();
subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver);
}
else
reader.ReadNext(); // }

var dateHistogram = new DateHistogramBucket(subAggregates)
{
Expand Down
34 changes: 34 additions & 0 deletions src/Tests/Tests.Reproduce/GithubIssue3673.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Elastic.Xunit.XunitPlumbing;
using FluentAssertions;
using Nest;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;

namespace Tests.Reproduce
{
public class GithubIssue3673 : IClusterFixture<ReadOnlyCluster>
{
private readonly ReadOnlyCluster _cluster;

public GithubIssue3673(ReadOnlyCluster cluster) => _cluster = cluster;

[I]
public void DeserializeDateAggregation()
{
Action action = () => _cluster.Client.Search<Project>(s => s
.Size(0)
.Aggregations(a => a
.DateHistogram("publication_year", st => st
.Field(o => o.StartedOn)
.Interval(DateInterval.Year)
.Format("yyyy")
.MinimumDocumentCount(0)
)
)
);

action.Should().NotThrow();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Tests.Aggregations.Bucket.AutoDateHistogram
*
* Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-autodatehistogram-aggregation.html[Auto Date Histogram Aggregation].
*/
[BlockedByIssue("https://github.com/elastic/elasticsearch/issues/39916")]
public class AutoDateHistogramAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
{
public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Tests.Aggregations.Bucket.DateHistogram
*
* Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram Aggregation].
*/
[BlockedByIssue("https://github.com/elastic/elasticsearch/issues/39916")]
public class DateHistogramAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
{
public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
Expand Down