ES: Change bool queries to use 'filter' clause (#7313)

Change all bool queries to use 'filter' clause instead of 'must' for
better performance
This commit is contained in:
lpic 2017-01-21 08:31:29 +01:00 committed by Torkel Ödegaard
parent 9151b4034a
commit a0c8380baf
4 changed files with 9 additions and 9 deletions

View File

@ -87,7 +87,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
var queryInterpolated = templateSrv.replace(queryString, {}, 'lucene');
var query = {
"bool": {
"must": [
"filter": [
{ "range": range },
{
"query_string": {

View File

@ -117,7 +117,7 @@ function (queryDef) {
filter = adhocFilters[i];
condition = {};
condition[filter.key] = filter.value;
query.query.bool.must.push({"term": condition});
query.query.bool.filter.push({"term": condition});
}
};
@ -133,7 +133,7 @@ function (queryDef) {
"size": 0,
"query": {
"bool": {
"must": [
"filter": [
{"range": this.getRangeFilter()},
{
"query_string": {
@ -226,13 +226,13 @@ function (queryDef) {
"size": 0,
"query": {
"bool": {
"must": [{"range": this.getRangeFilter()}]
"filter": [{"range": this.getRangeFilter()}]
}
}
};
if (queryDef.query) {
query.query.bool.must.push({
query.query.bool.filter.push({
"query_string": {
"analyze_wildcard": true,
"query": queryDef.query,

View File

@ -77,7 +77,7 @@ describe('ElasticDatasource', function() {
it('should json escape lucene query', function() {
var body = angular.fromJson(parts[1]);
expect(body.query.bool.must[1].query_string.query).to.be('escape\\:test');
expect(body.query.bool.filter[1].query_string.query).to.be('escape\\:test');
});
});

View File

@ -16,7 +16,7 @@ describe('ElasticQueryBuilder', function() {
bucketAggs: [{type: 'date_histogram', field: '@timestamp', id: '1'}],
});
expect(query.query.bool.must[0].range["@timestamp"].gte).to.be("$timeFrom");
expect(query.query.bool.filter[0].range["@timestamp"].gte).to.be("$timeFrom");
expect(query.aggs["1"].date_histogram.extended_bounds.min).to.be("$timeFrom");
});
@ -32,7 +32,7 @@ describe('ElasticQueryBuilder', function() {
bucketAggs: [{type: 'date_histogram', field: '@timestamp', id: '1'}],
});
expect(query.query.bool.must[0].range["@timestamp"].gte).to.be("$timeFrom");
expect(query.query.bool.filter[0].range["@timestamp"].gte).to.be("$timeFrom");
expect(query.aggs["1"].date_histogram.extended_bounds.min).to.be("$timeFrom");
});
@ -258,6 +258,6 @@ describe('ElasticQueryBuilder', function() {
{key: 'key1', operator: '=', value: 'value1'}
]);
expect(query.query.bool.must[2].term["key1"]).to.be("value1");
expect(query.query.bool.filter[2].term["key1"]).to.be("value1");
});
});