mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(elasticsearch): refactoring of #3321
This commit is contained in:
parent
f1cb8f2f25
commit
db9c288050
@ -13,7 +13,7 @@ function (angular, _, config) {
|
||||
|
||||
$scope.httpConfigPartialSrc = 'app/features/org/partials/datasourceHttpConfig.html';
|
||||
|
||||
var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {'elasticsearchVersion': 2} };
|
||||
var defaults = {name: '', type: 'graphite', url: '', access: 'proxy', jsonData: {}};
|
||||
|
||||
$scope.indexPatternTypes = [
|
||||
{name: 'No pattern', value: undefined},
|
||||
@ -24,8 +24,7 @@ function (angular, _, config) {
|
||||
{name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY'},
|
||||
];
|
||||
|
||||
$scope.elasticsearchVersions = [
|
||||
{name: '0.x', value: 0},
|
||||
$scope.esVersions = [
|
||||
{name: '1.x', value: 1},
|
||||
{name: '2.x', value: 2},
|
||||
];
|
||||
|
@ -23,11 +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.esVersion = datasource.jsonData.esVersion;
|
||||
this.indexPattern = new IndexPattern(datasource.index, datasource.jsonData.interval);
|
||||
this.queryBuilder = new ElasticQueryBuilder({
|
||||
timeField: this.timeField,
|
||||
elasticsearchVersion: this.elasticsearchVersion
|
||||
esVersion: this.esVersion,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,10 @@
|
||||
<div class="tight-form last">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 144px">
|
||||
Elasticsearch version
|
||||
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>
|
||||
<select class="input-medium tight-form-input" ng-model="current.jsonData.esVersion" ng-options="f.value as f.name for f in esVersions"></select>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
|
@ -5,15 +5,14 @@ function () {
|
||||
|
||||
function ElasticQueryBuilder(options) {
|
||||
this.timeField = options.timeField;
|
||||
this.elasticsearchVersion = options.elasticsearchVersion;
|
||||
this.esVersion = options.esVersion;
|
||||
}
|
||||
|
||||
ElasticQueryBuilder.prototype.getRangeFilter = function() {
|
||||
var filter = {};
|
||||
filter[this.timeField] = {"gte": "$timeFrom", "lte": "$timeTo"};
|
||||
|
||||
// elastic search versions 2.x require the time format to be specified
|
||||
if (this.elasticsearchVersion >= 2) {
|
||||
if (this.esVersion >= 2) {
|
||||
filter[this.timeField]["format"] = "epoch_millis";
|
||||
}
|
||||
|
||||
@ -137,8 +136,7 @@ function () {
|
||||
"min_doc_count": 0,
|
||||
"extended_bounds": { "min": "$timeFrom", "max": "$timeTo" }
|
||||
};
|
||||
// elastic search versions 2.x require the time format to be specified
|
||||
if (this.elasticsearchVersion >= 2) {
|
||||
if (this.esVersion >= 2) {
|
||||
esAgg["date_histogram"]["format"] = "epoch_millis";
|
||||
}
|
||||
break;
|
||||
|
@ -39,7 +39,7 @@ describe('ElasticQueryBuilder', function() {
|
||||
it('with es1.x and es2.x date histogram queries check time format', function() {
|
||||
var builder_2x = new ElasticQueryBuilder({
|
||||
timeField: '@timestamp',
|
||||
elasticsearchVersion: 2
|
||||
esVersion: 2
|
||||
});
|
||||
|
||||
var query_params = {
|
||||
@ -59,7 +59,7 @@ describe('ElasticQueryBuilder', function() {
|
||||
it('with es1.x and es2.x range filter check time format', function() {
|
||||
var builder_2x = new ElasticQueryBuilder({
|
||||
timeField: '@timestamp',
|
||||
elasticsearchVersion: 2
|
||||
esVersion: 2
|
||||
});
|
||||
|
||||
// format should not be specified in 1.x queries
|
||||
|
Loading…
Reference in New Issue
Block a user