Skip to content

Commit d90efa5

Browse files
committed
#fix 643 numeric terms we're not showing up on .Key on buckets (null)
1 parent 844caad commit d90efa5

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/Nest/Resolvers/Converters/AggregationConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ private IAggregation GetDateHistogramAggregation(JsonReader reader, JsonSerializ
170170
private IAggregation GetKeyedBucketItem(JsonReader reader, JsonSerializer serializer)
171171
{
172172
reader.Read();
173-
var key = reader.Value as string;
173+
var key = reader.Value;
174174
reader.Read();
175175
var property = reader.Value as string;
176176
if (property == "from" || property == "to")
177-
return GetRangeAggregation(reader, serializer, key);
177+
return GetRangeAggregation(reader, serializer, key.ToString());
178178

179179

180180
var keyItem = new KeyItem();
181-
keyItem.Key = key;
181+
keyItem.Key = key.ToString();
182182
reader.Read(); //doc_count;
183183
var docCount = reader.Value as long?;
184184
keyItem.DocCount = docCount.GetValueOrDefault(0);

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
<Compile Include="RawCalls\DynamicNullTests.cs" />
162162
<Compile Include="Mapping\NotAnalyzedTest.cs" />
163163
<Compile Include="RawCalls\ReturnTypesTest.cs" />
164+
<Compile Include="Reproduce\Reproduce643Tests.cs" />
164165
<Compile Include="Reproduce\Reproduce628Tests.cs" />
165166
<Compile Include="Reproduce\Reproduce487Tests.cs" />
166167
<Compile Include="Reproduce\Reproduce437Tests.cs" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using Nest.Tests.MockData;
6+
using Nest.Tests.MockData.Domain;
7+
using NUnit.Framework;
8+
using System.Diagnostics;
9+
using FluentAssertions;
10+
11+
namespace Nest.Tests.Integration.Reproduce
12+
{
13+
[TestFixture]
14+
public class Reproduce643Tests : IntegrationTests
15+
{
16+
17+
/// <summary>
18+
/// https://github.com/Mpdreamz/NEST/issues/643
19+
/// </summary>
20+
[Test]
21+
public void TermsAggregationOnLongFieldShouldHaveKeysOnBucket()
22+
{
23+
var searchResult = this._client.Search<ElasticsearchProject>(s => s
24+
.Size(0)
25+
.Aggregations(aggs=>aggs
26+
.Terms("numericTerms", t=>t
27+
.Field(p=>p.LongValue)
28+
.Size(10)
29+
)
30+
)
31+
);
32+
33+
searchResult.IsValid.Should().BeTrue();
34+
var terms = searchResult.Aggs.Terms("numericTerms");
35+
terms.Items.Should().NotBeEmpty().And.NotContain(p => p.Key.IsNullOrEmpty());
36+
37+
}
38+
39+
}
40+
}

0 commit comments

Comments
 (0)