Skip to content

Commit 0300d7c

Browse files
committed
Merge pull request #1706 from elastic/fix/datehistogramitem
Separate types for histogram and date histogram items
2 parents f05b440 + bf31083 commit 0300d7c

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

src/Nest/Aggregations/AggregationJsonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private IAggregation GetDateHistogramAggregation(JsonReader reader, JsonSerializ
274274
var docCount = (reader.Value as long?).GetValueOrDefault(0);
275275
reader.Read();
276276

277-
var dateHistogram = new HistogramItem() { Key = key, KeyAsString = keyAsString, DocCount = docCount };
277+
var dateHistogram = new DateHistogramItem() { Key = key, KeyAsString = keyAsString, DocCount = docCount };
278278
dateHistogram.Aggregations = this.GetNestedAggregations(reader, serializer);
279279
return dateHistogram;
280280

src/Nest/Aggregations/AggregationsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ public Bucket<RangeItem> GeoDistance(string key)
179179
: new Bucket<RangeItem> {Items = bucket.Items.OfType<RangeItem>().ToList()};
180180
}
181181

182-
public Bucket<HistogramItem> DateHistogram(string key)
182+
public Bucket<DateHistogramItem> DateHistogram(string key)
183183
{
184184
var bucket = this.TryGet<Bucket>(key);
185185
return bucket == null
186186
? null
187-
: new Bucket<HistogramItem> {Items = bucket.Items.OfType<HistogramItem>().ToList()};
187+
: new Bucket<DateHistogramItem> {Items = bucket.Items.OfType<DateHistogramItem>().ToList()};
188188
}
189189
}
190190
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Nest
8+
{
9+
public class DateHistogramItem : HistogramItem
10+
{
11+
// Get a DateTime form of the returned key
12+
public DateTime Date => new DateTime(1970, 1, 1).AddMilliseconds(0 + this.Key);
13+
}
14+
}

src/Nest/Aggregations/Bucket/Histogram/HistogramItem.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ public HistogramItem(IDictionary<string, IAggregation> aggregations) : base(aggr
1010

1111
public long Key { get; set; }
1212
public string KeyAsString { get; set; }
13-
14-
/// <summary>
15-
/// Get a DateTime form of the returned key, only make sense on date_histogram aggregations.
16-
/// </summary>
17-
public DateTime Date => new DateTime(1970, 1, 1).AddMilliseconds(0 + this.Key);
18-
1913
public long DocCount { get; set; }
2014
}
2115
}

src/Nest/Nest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Reference Include="System.ServiceModel" />
5656
</ItemGroup>
5757
<ItemGroup>
58+
<Compile Include="Aggregations\Bucket\DateHistogram\DateHistogramItem.cs" />
5859
<Compile Include="Aggregations\Bucket\DocCountBucket.cs" />
5960
<Compile Include="Aggregations\Bucket\Sampler\SamplerAggregation.cs" />
6061
<Compile Include="Aggregations\Bucket\Sampler\SamplerAggregationExecutionHint.cs" />

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: u
2+
mode: i
33
# the elasticsearch version that should be started
44
elasticsearch_version: 2.0.1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)