Browse Source

Merge pull request #14179 from mattiarossi/master

Add support for offset in date histogram aggregation
Marcus Efraimsson 7 years ago
parent
commit
acb45867f8

+ 1 - 0
pkg/tsdb/elasticsearch/client/models.go

@@ -240,6 +240,7 @@ type DateHistogramAgg struct {
 	Missing        *string         `json:"missing,omitempty"`
 	ExtendedBounds *ExtendedBounds `json:"extended_bounds"`
 	Format         string          `json:"format"`
+	Offset         string          `json:"offset,omitempty"`
 }
 
 // FiltersAggregation represents a filters aggregation

+ 4 - 0
pkg/tsdb/elasticsearch/time_series_query.go

@@ -134,6 +134,10 @@ func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFro
 			a.Interval = "$__interval"
 		}
 
+		if offset, err := bucketAgg.Settings.Get("offset").String(); err == nil {
+			a.Offset = offset
+		}
+
 		if missing, err := bucketAgg.Settings.Get("missing").String(); err == nil {
 			a.Missing = &missing
 		}

+ 10 - 0
public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html

@@ -70,6 +70,16 @@
 			</label>
 			<input class="gf-form-input max-width-12" type="number" ng-model="agg.settings.trimEdges" ng-change="onChangeInternal()">
 		</div>
+		<div class="gf-form offset-width-7">
+			<label class="gf-form-label width-10">
+				Offset
+				<info-popover mode="right-normal">
+					Change the start value of each bucket by the specified positive (+) or negative offset (-) duration, such as 1h for an hour, or 1d for a day
+				</info-popover>
+			</label>
+			<input class="gf-form-input max-width-12" type="text" ng-model="agg.settings.offset" ng-change="onChangeInternal()">
+		</div>
+
 	</div>
 
 	<div ng-if="agg.type === 'histogram'">

+ 4 - 0
public/app/plugins/datasource/elasticsearch/query_builder.ts

@@ -72,6 +72,10 @@ export class ElasticQueryBuilder {
     esAgg.extended_bounds = { min: '$timeFrom', max: '$timeTo' };
     esAgg.format = 'epoch_millis';
 
+    if (settings.offset !== '') {
+      esAgg.offset = settings.offset;
+    }
+
     if (esAgg.interval === 'auto') {
       esAgg.interval = '$__interval';
     }