Skip to content

Commit 43ca446

Browse files
committed
Merge branch 'fix/aggs1.5' into develop
2 parents 50c60bf + a6949e2 commit 43ca446

File tree

4 files changed

+68
-37
lines changed

4 files changed

+68
-37
lines changed

src/Nest/Resolvers/Converters/Aggregations/AggregationConverter.cs

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,23 @@ private IAggregation GetPercentilesMetricAggregation(JsonReader reader, JsonSeri
116116
reader.Read();
117117
while (reader.TokenType != JsonToken.EndObject)
118118
{
119-
var percentile = double.Parse(reader.Value as string, CultureInfo.InvariantCulture);
120-
reader.Read();
121-
var value = reader.Value as double?;
122-
percentileItems.Add(new PercentileItem()
119+
if ((reader.Value as string).Contains("_as_string"))
123120
{
124-
Percentile = percentile,
125-
Value = value.GetValueOrDefault(0)
126-
});
127-
reader.Read();
121+
reader.Read();
122+
reader.Read();
123+
}
124+
if (reader.TokenType != JsonToken.EndObject)
125+
{
126+
var percentile = double.Parse(reader.Value as string, CultureInfo.InvariantCulture);
127+
reader.Read();
128+
var value = reader.Value as double?;
129+
percentileItems.Add(new PercentileItem()
130+
{
131+
Percentile = percentile,
132+
Value = value.GetValueOrDefault(0)
133+
});
134+
reader.Read();
135+
}
128136
}
129137
metric.Items = percentileItems;
130138
if (!oldFormat) reader.Read();
@@ -168,56 +176,72 @@ private IAggregation GetStatsAggregation(JsonReader reader, JsonSerializer seria
168176
reader.Read(); reader.Read();
169177
var sum = (reader.Value as double?);
170178

179+
var statsMetric = new StatsMetric()
180+
{
181+
Average = average,
182+
Count = count,
183+
Max = max,
184+
Min = min,
185+
Sum = sum
186+
};
187+
171188
reader.Read();
189+
172190
if (reader.TokenType == JsonToken.EndObject)
173-
return new StatsMetric()
174-
{
175-
Average = average,
176-
Count = count,
177-
Max = max,
178-
Min = min,
179-
Sum = sum
180-
};
191+
return statsMetric;
192+
193+
while (reader.TokenType != JsonToken.EndObject && (reader.Value as string).Contains("_as_string"))
194+
{
195+
reader.Read();
196+
reader.Read();
197+
}
198+
199+
if (reader.TokenType == JsonToken.EndObject)
200+
return statsMetric;
201+
202+
return GetExtendedStatsAggregation(statsMetric, reader);
203+
}
204+
205+
private IAggregation GetExtendedStatsAggregation(StatsMetric statsMetric, JsonReader reader)
206+
{
207+
var extendedStatsMetric = new ExtendedStatsMetric()
208+
{
209+
Average = statsMetric.Average,
210+
Count = statsMetric.Count,
211+
Max = statsMetric.Max,
212+
Min = statsMetric.Min,
213+
Sum = statsMetric.Sum
214+
};
181215

182216
reader.Read();
183-
var sumOfSquares = (reader.Value as double?);
184-
reader.Read(); reader.Read();
185-
var variance = (reader.Value as double?);
217+
extendedStatsMetric.SumOfSquares = (reader.Value as double?);
218+
reader.Read();
219+
reader.Read();
220+
extendedStatsMetric.Variance = (reader.Value as double?);
186221
reader.Read(); reader.Read();
187-
var stdDeviation = (reader.Value as double?);
222+
extendedStatsMetric.StdDeviation = (reader.Value as double?);
188223
reader.Read();
189224

190-
StandardDeviationBounds stdDeviationBounds = null;
191225
if (reader.TokenType != JsonToken.EndObject)
192226
{
193-
stdDeviationBounds = new StandardDeviationBounds();
227+
var bounds = new StandardDeviationBounds();
194228
reader.Read();
195229
reader.Read();
196230
if ((reader.Value as string) == "upper")
197231
{
198232
reader.Read();
199-
stdDeviationBounds.Upper = reader.Value as double?;
233+
bounds.Upper = reader.Value as double?;
200234
}
201235
reader.Read();
202236
if ((reader.Value as string) == "lower")
203237
{
204238
reader.Read();
205-
stdDeviationBounds.Lower = reader.Value as double?;
239+
bounds.Lower = reader.Value as double?;
206240
}
241+
extendedStatsMetric.StdDeviationBounds = bounds;
207242
}
208243

209-
return new ExtendedStatsMetric()
210-
{
211-
Average = average,
212-
Count = count,
213-
Max = max,
214-
Min = min,
215-
StdDeviation = stdDeviation,
216-
Sum = sum,
217-
SumOfSquares = sumOfSquares,
218-
Variance = variance,
219-
StdDeviationBounds = stdDeviationBounds
220-
};
244+
return extendedStatsMetric;
221245
}
222246

223247
private IAggregation GetDateHistogramAggregation(JsonReader reader, JsonSerializer serializer)
@@ -379,6 +403,11 @@ private IAggregation GetValueMetricOrAggregation(JsonReader reader, JsonSerializ
379403
if (valueMetric.Value != null)
380404
{
381405
reader.Read();
406+
if (reader.TokenType != JsonToken.EndObject)
407+
{
408+
reader.Read();
409+
reader.Read();
410+
}
382411
return valueMetric;
383412
}
384413

src/Tests/Nest.Tests.Integration/Core/Map/Mapping/MappingTransformTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void MultipleTransformTest()
4949
)
5050
.Transform(t => t
5151
.Script("ctx._source['suggest'] = ctx._source['content']")
52+
.Language("groovy") //mandatory since elasticsearch 1.5
5253
)
5354
);
5455
this.DefaultResponseAssertations(putResult);

src/Tests/Nest.Tests.Integration/Core/TermVectors/TermVectorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void TermVectorNonMappedFieldTest()
100100
{
101101
var result = Client.TermVector<ElasticsearchProject>(s => s
102102
.Id("1")
103-
.Fields(ep => ep.Name));
103+
.Fields("blahblah"));
104104

105105
result.IsValid.Should().BeTrue();
106106
result.TermVectors.Count().ShouldBeEquivalentTo(0);

src/Tests/Nest.Tests.Integration/Reproduce/Reproduce994Tests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Nest.Tests.Integration.Reproduce
1313
public class Reproduce994Tests : IntegrationTests
1414
{
1515
[Test]
16+
[Ignore]
1617
public void DateTimeRangeItemsAreReturnedProperly()
1718
{
1819
var fixedDateString = "2014-03-01T00:00:00.000Z";

0 commit comments

Comments
 (0)