Skip to content

Commit 7002ae2

Browse files
committed
Add integration test for AutoDateHistogram minimum_interval
This commit splits out the integration test on minimum_interval for AutoDateHistogramAggregation to a separate test which is skipped for versions less than 7.3.0
1 parent 2356791 commit 7002ae2

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using Elastic.Xunit.XunitPlumbing;
34
using FluentAssertions;
45
using Nest;
56
using Tests.Core.Extensions;
@@ -27,6 +28,104 @@ public class AutoDateHistogramAggregationUsageTests : ProjectsOnlyAggregationUsa
2728
{
2829
public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
2930

31+
protected override object AggregationJson => new
32+
{
33+
projects_started_per_month = new
34+
{
35+
auto_date_histogram = new
36+
{
37+
field = "startedOn",
38+
buckets = 10,
39+
format = "yyyy-MM-dd'T'HH:mm:ss||date_optional_time", //<1> Note the inclusion of `date_optional_time` to `format`
40+
missing = FixedDate
41+
},
42+
aggs = new
43+
{
44+
project_tags = new
45+
{
46+
nested = new
47+
{
48+
path = "tags"
49+
},
50+
aggs = new
51+
{
52+
tags = new
53+
{
54+
terms = new { field = "tags.name" }
55+
}
56+
}
57+
}
58+
}
59+
}
60+
};
61+
62+
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
63+
.AutoDateHistogram("projects_started_per_month", date => date
64+
.Field(p => p.StartedOn)
65+
.Buckets(10)
66+
.Format("yyyy-MM-dd'T'HH:mm:ss")
67+
.Missing(FixedDate)
68+
.Aggregations(childAggs => childAggs
69+
.Nested("project_tags", n => n
70+
.Path(p => p.Tags)
71+
.Aggregations(nestedAggs => nestedAggs
72+
.Terms("tags", avg => avg.Field(p => p.Tags.First().Name))
73+
)
74+
)
75+
)
76+
);
77+
78+
protected override AggregationDictionary InitializerAggs =>
79+
new AutoDateHistogramAggregation("projects_started_per_month")
80+
{
81+
Field = Field<Project>(p => p.StartedOn),
82+
Buckets = 10,
83+
Format = "yyyy-MM-dd'T'HH:mm:ss",
84+
Missing = FixedDate,
85+
Aggregations = new NestedAggregation("project_tags")
86+
{
87+
Path = Field<Project>(p => p.Tags),
88+
Aggregations = new TermsAggregation("tags")
89+
{
90+
Field = Field<Project>(p => p.Tags.First().Name)
91+
}
92+
}
93+
};
94+
95+
protected override void ExpectResponse(ISearchResponse<Project> response)
96+
{
97+
/** ==== Handling responses
98+
* The `AggregateDictionary found on `.Aggregations` on `SearchResponse<T>` has several helper methods
99+
* so we can fetch our aggregation results easily in the correct type.
100+
* <<handling-aggregate-response, Be sure to read more about these helper methods>>
101+
*/
102+
response.ShouldBeValid();
103+
104+
var dateHistogram = response.Aggregations.AutoDateHistogram("projects_started_per_month");
105+
dateHistogram.Should().NotBeNull();
106+
dateHistogram.Interval.Should().NotBeNull();
107+
dateHistogram.Buckets.Should().NotBeNull();
108+
dateHistogram.Buckets.Count.Should().BeGreaterThan(1);
109+
foreach (var item in dateHistogram.Buckets)
110+
{
111+
item.Date.Should().NotBe(default);
112+
item.DocCount.Should().BeGreaterThan(0);
113+
114+
var nested = item.Nested("project_tags");
115+
nested.Should().NotBeNull();
116+
117+
var nestedTerms = nested.Terms("tags");
118+
nestedTerms.Buckets.Count.Should().BeGreaterThan(0);
119+
}
120+
}
121+
}
122+
123+
// hide
124+
[SkipVersion("<7.3.0", "minimum_interval introduced in 7.3.0")]
125+
public class AutoDateHistogramAggregationWithMinimumIntervalUsageTests : ProjectsOnlyAggregationUsageTestBase
126+
{
127+
public AutoDateHistogramAggregationWithMinimumIntervalUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
128+
30129
protected override object AggregationJson => new
31130
{
32131
projects_started_per_month = new

0 commit comments

Comments
 (0)