diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 9d6b8e4c834..374fc9da90d 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -159,7 +159,10 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes if (target.hide) {return;} var esQuery = angular.toJson(this.queryBuilder.build(target)); - esQuery = esQuery.replace("$lucene_query", target.query || '*'); + var luceneQuery = angular.toJson(target.query || '*'); + // remove inner quotes + luceneQuery = luceneQuery.substr(1, luceneQuery.length - 2); + esQuery = esQuery.replace("$lucene_query", luceneQuery); payload += header + '\n' + esQuery + '\n'; sentTargets.push(target); diff --git a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts index aecb16501b7..a5e55abe4dd 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts @@ -42,16 +42,15 @@ describe('ElasticDatasource', function() { }); describe('When issueing metric query with interval pattern', function() { + var requestOptions, parts, header; + beforeEach(function() { ctx.ds = new ctx.service({ url: 'http://es.com', index: '[asd-]YYYY.MM.DD', jsonData: { interval: 'Daily' } }); - }); - it('should translate index pattern to current day', function() { - var requestOptions; ctx.backendSrv.datasourceRequest = function(options) { requestOptions = options; return ctx.$q.when({data: {responses: []}}); @@ -62,13 +61,22 @@ describe('ElasticDatasource', function() { from: moment([2015, 4, 30, 10]), to: moment([2015, 5, 1, 10]) }, - targets: [{ bucketAggs: [], metrics: [] }] + targets: [{ bucketAggs: [], metrics: [], query: 'escape\\:test' }] }); ctx.$rootScope.$apply(); - var parts = requestOptions.data.split('\n'); - var header = angular.fromJson(parts[0]); + + parts = requestOptions.data.split('\n'); + header = angular.fromJson(parts[0]); + }); + + it('should translate index pattern to current day', function() { expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']); }); + + it('should json escape lucene query', function() { + var body = angular.fromJson(parts[1]); + expect(body.query.filtered.query.query_string.query).to.be('escape\\:test'); + }); }); }); diff --git a/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts index ccebef59a12..8f662bb075f 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts @@ -8,7 +8,7 @@ declare var IndexPattern: any; describe('IndexPattern', function() { - describe.only('when getting index for today', function() { + describe('when getting index for today', function() { it('should return correct index name', function() { var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily'); var expected = 'asd-' + moment().format('YYYY.MM.DD');