File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
main/java/org/elasticsearch/xpack/rollup
test/java/org/elasticsearch/xpack/rollup
src/test/resources/rest-api-spec/test/rollup Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 66package org .elasticsearch .xpack .rollup ;
77
88
9+ import org .elasticsearch .common .Strings ;
910import org .elasticsearch .common .io .stream .BytesStreamOutput ;
1011import org .elasticsearch .common .io .stream .NamedWriteableAwareStreamInput ;
1112import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
@@ -227,6 +228,9 @@ private static List<AggregationBuilder> translateDateHistogram(DateHistogramAggr
227228 if (source .extendedBounds () != null ) {
228229 rolledDateHisto .extendedBounds (source .extendedBounds ());
229230 }
231+ if (Strings .isNullOrEmpty (source .format ()) == false ) {
232+ rolledDateHisto .format (source .format ());
233+ }
230234 rolledDateHisto .keyed (source .keyed ());
231235 rolledDateHisto .minDocCount (source .minDocCount ());
232236 rolledDateHisto .order (source .order ());
Original file line number Diff line number Diff line change @@ -108,7 +108,25 @@ public void testBasicDateHisto() {
108108 fail ("Unexpected query builder in filter conditions" );
109109 }
110110 }
111+ }
112+
113+ public void testFormattedDateHisto () {
114+ DateHistogramAggregationBuilder histo = new DateHistogramAggregationBuilder ("test_histo" );
115+ histo .dateHistogramInterval (new DateHistogramInterval ("1d" ))
116+ .field ("foo" )
117+ .extendedBounds (new ExtendedBounds (0L , 1000L ))
118+ .format ("yyyy-MM-dd" )
119+ .subAggregation (new MaxAggregationBuilder ("the_max" ).field ("max_field" ));
120+ List <QueryBuilder > filterConditions = new ArrayList <>();
121+
122+ List <AggregationBuilder > translated = translateAggregation (histo , filterConditions , namedWriteableRegistry );
123+ assertThat (translated .size (), equalTo (1 ));
124+ assertThat (translated .get (0 ), Matchers .instanceOf (DateHistogramAggregationBuilder .class ));
125+ DateHistogramAggregationBuilder translatedHisto = (DateHistogramAggregationBuilder )translated .get (0 );
111126
127+ assertThat (translatedHisto .dateHistogramInterval (), equalTo (new DateHistogramInterval ("1d" )));
128+ assertThat (translatedHisto .format (), equalTo ("yyyy-MM-dd" ));
129+ assertThat (translatedHisto .field (), equalTo ("foo.date_histogram.timestamp" ));
112130 }
113131
114132 public void testSimpleMetric () {
Original file line number Diff line number Diff line change @@ -152,6 +152,32 @@ setup:
152152 - match : { aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z" }
153153 - match : { aggregations.histo.buckets.3.doc_count: 20 }
154154
155+ ---
156+ " Formatted Date Histo " :
157+
158+ - do :
159+ xpack.rollup.rollup_search :
160+ index : " foo_rollup"
161+ body :
162+ size : 0
163+ aggs :
164+ histo :
165+ date_histogram :
166+ field : " timestamp"
167+ interval : " 1h"
168+ time_zone : " UTC"
169+ format : " yyyy-MM-dd"
170+
171+ - length : { aggregations.histo.buckets: 4 }
172+ - match : { aggregations.histo.buckets.0.key_as_string: "2017-01-01" }
173+ - match : { aggregations.histo.buckets.0.doc_count: 1 }
174+ - match : { aggregations.histo.buckets.1.key_as_string: "2017-01-01" }
175+ - match : { aggregations.histo.buckets.1.doc_count: 2 }
176+ - match : { aggregations.histo.buckets.2.key_as_string: "2017-01-01" }
177+ - match : { aggregations.histo.buckets.2.doc_count: 10 }
178+ - match : { aggregations.histo.buckets.3.key_as_string: "2017-01-01" }
179+ - match : { aggregations.histo.buckets.3.doc_count: 20 }
180+
155181---
156182" Empty aggregation " :
157183
You can’t perform that action at this time.
0 commit comments