mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
keep track of elastic search version and generate query according to version
This commit is contained in:
@@ -23,9 +23,11 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
||||
this.name = datasource.name;
|
||||
this.index = datasource.index;
|
||||
this.timeField = datasource.jsonData.timeField;
|
||||
this.elasticsearchVersion = datasource.jsonData.elasticsearchVersion;
|
||||
this.indexPattern = new IndexPattern(datasource.index, datasource.jsonData.interval);
|
||||
this.queryBuilder = new ElasticQueryBuilder({
|
||||
timeField: this.timeField
|
||||
timeField: this.timeField,
|
||||
elasticsearchVersion: this.elasticsearchVersion
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form last">
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 144px">
|
||||
Time field name
|
||||
@@ -31,3 +31,14 @@
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form last">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 144px">
|
||||
Elasticsearch version
|
||||
</li>
|
||||
<li>
|
||||
<select class="input-medium tight-form-input" ng-model="current.jsonData.elasticsearchVersion" ng-options="f.value as f.name for f in elasticsearchVersions"></select>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
||||
@@ -6,11 +6,18 @@ function (angular) {
|
||||
|
||||
function ElasticQueryBuilder(options) {
|
||||
this.timeField = options.timeField;
|
||||
this.elasticsearchVersion = options.elasticsearchVersion;
|
||||
}
|
||||
|
||||
ElasticQueryBuilder.prototype.getRangeFilter = function() {
|
||||
var filter = {};
|
||||
filter[this.timeField] = {"gte": "$timeFrom", "lte": "$timeTo"};
|
||||
|
||||
// elastic search versions above 2.0 require the time format to be specified
|
||||
if (this.elasticsearchVersion >= 2) {
|
||||
filter[this.timeField]["format"] = "epoch_millis";
|
||||
}
|
||||
|
||||
return filter;
|
||||
};
|
||||
|
||||
@@ -129,6 +136,10 @@ function (angular) {
|
||||
"min_doc_count": 0,
|
||||
"extended_bounds": { "min": "$timeFrom", "max": "$timeTo" }
|
||||
};
|
||||
// elastic search versions above 2.0 require the time format to be specified
|
||||
if (this.elasticsearchVersion >= 2) {
|
||||
esAgg["date_histogram"]["format"] = "epoch_millis";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'filters': {
|
||||
|
||||
Reference in New Issue
Block a user