forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When only one side of the range is infinite, we never add a condition to the script filter for that half of the range, so elasticsearch treats it as infinite. When both sides of the range are infinite, we use a match_all filter instead of a conditional script to define the range.
- Loading branch information
Showing
5 changed files
with
138 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
describe('ui/filter_bar/lib', function () { | ||
describe('mapMatchAll()', function () { | ||
const expect = require('expect.js'); | ||
const ngMock = require('ngMock'); | ||
let resolvePromises; | ||
let mapMatchAll; | ||
let filter; | ||
|
||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject(function (Private, $rootScope) { | ||
resolvePromises = () => $rootScope.$apply(); | ||
mapMatchAll = Private(require('ui/filter_bar/lib/mapMatchAll')); | ||
filter = { | ||
match_all: {}, | ||
meta: { | ||
field: 'foo', | ||
formattedValue: 'bar' | ||
} | ||
}; | ||
})); | ||
|
||
context('when given a filter that is not match_all', function () { | ||
it('filter is rejected', function (done) { | ||
delete filter.match_all; | ||
mapMatchAll(filter).catch(result => { | ||
expect(result).to.be(filter); | ||
done(); | ||
}); | ||
resolvePromises(); | ||
}); | ||
}); | ||
|
||
context('when given a match_all filter', function () { | ||
let result; | ||
beforeEach(function () { | ||
mapMatchAll(filter).then(r => result = r); | ||
resolvePromises(); | ||
}); | ||
|
||
it('key is set to meta field', function () { | ||
expect(result).to.have.property('key', filter.meta.field); | ||
}); | ||
|
||
it('value is set to meta formattedValue', function () { | ||
expect(result).to.have.property('value', filter.meta.formattedValue); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
define(function (require) { | ||
return function mapMatchAllProvider(Promise) { | ||
return function (filter) { | ||
if (filter.match_all) { | ||
const key = filter.meta.field; | ||
const value = filter.meta.formattedValue || 'all'; | ||
return Promise.resolve({ key, value }); | ||
} | ||
return Promise.reject(filter); | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
const OPERANDS_IN_RANGE = 2; | ||
|
||
return function buildRangeFilter(field, params, indexPattern, formattedValue) { | ||
var filter = { meta: { index: indexPattern.id } }; | ||
const filter = { meta: { index: indexPattern.id } }; | ||
if (formattedValue) filter.meta.formattedValue = formattedValue; | ||
|
||
params = _.clone(params); | ||
|
||
if (params.gte && params.gt) throw new Error('gte and gt are mutually exclusive'); | ||
if (params.lte && params.lt) throw new Error('lte and lt are mutually exclusive'); | ||
if ('gte' in params && 'gt' in params) throw new Error('gte and gt are mutually exclusive'); | ||
if ('lte' in params && 'lt' in params) throw new Error('lte and lt are mutually exclusive'); | ||
|
||
const totalInfinite = ['gt', 'lt'].reduce((totalInfinite, op) => { | ||
const key = op in params ? op : `${op}e`; | ||
const isInfinite = Math.abs(params[key]) === Infinity; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
epixa
Author
Owner
|
||
|
||
if (isInfinite) { | ||
totalInfinite++; | ||
delete params[key]; | ||
} | ||
|
||
if (field.scripted) { | ||
var operators = { | ||
return totalInfinite; | ||
}, 0); | ||
|
||
if (totalInfinite === OPERANDS_IN_RANGE) { | ||
filter.match_all = {}; | ||
filter.meta.field = field.name; | ||
} else if (field.scripted) { | ||
const operators = { | ||
gt: '>', | ||
gte: '>=', | ||
lte: '<=', | ||
lt: '<', | ||
}; | ||
|
||
var script = _.map(params, function (val, key) { | ||
const script = _.map(params, function (val, key) { | ||
return '(' + field.script + ')' + operators[key] + key; | ||
}).join(' && '); | ||
|
||
var value = _.map(params, function (val, key) { | ||
const value = _.map(params, function (val, key) { | ||
return operators[key] + field.format.convert(val); | ||
}).join(' '); | ||
|
||
|
@@ -32,6 +49,7 @@ define(function (require) { | |
filter.range = {}; | ||
filter.range[field.name] = params; | ||
} | ||
|
||
return filter; | ||
}; | ||
}); |
Is there a reason that
isFinite()
wouldn't work here?