diff --git a/src/ui/public/filter_manager/__tests__/filter_manager.js b/src/ui/public/filter_manager/__tests__/filter_manager.js index 618b969b9589b..a27b56ff6926c 100644 --- a/src/ui/public/filter_manager/__tests__/filter_manager.js +++ b/src/ui/public/filter_manager/__tests__/filter_manager.js @@ -114,13 +114,13 @@ describe('Filter Manager', function () { checkAddFilters(0, null, 3); expect(appState.filters).to.have.length(2); - let scriptedField = {name: 'scriptedField', scripted: true, script: 1}; + let scriptedField = {name: 'scriptedField', scripted: true, script: 1, lang: 'painless'}; filterManager.add(scriptedField, 1, '+', 'myIndex'); checkAddFilters(1, [{ meta: {index: 'myIndex', negate: false, field: 'scriptedField'}, script: { script: { - inline: '(' + scriptedField.script + ') == value', + inline: '(' + scriptedField.script + ') == params.value', lang: scriptedField.lang, params: {value: 1} } diff --git a/src/ui/public/filter_manager/filter_manager.js b/src/ui/public/filter_manager/filter_manager.js index c856ab0c07746..faf073cdd74df 100644 --- a/src/ui/public/filter_manager/filter_manager.js +++ b/src/ui/public/filter_manager/filter_manager.js @@ -54,11 +54,13 @@ export default function (Private) { break; default: if (field.scripted) { + // painless expects params.value while groovy and expression languages expect value. + const valueClause = field.lang === 'painless' ? 'params.value' : 'value'; filter = { meta: { negate: negate, index: index, field: fieldName }, script: { script: { - inline: '(' + field.script + ') == value', + inline: '(' + field.script + ') == ' + valueClause, lang: field.lang, params: { value: value @@ -82,3 +84,4 @@ export default function (Private) { return filterManager; }; + diff --git a/src/ui/public/filter_manager/lib/phrase.js b/src/ui/public/filter_manager/lib/phrase.js index fbc2f45657d01..8fd6eec931d19 100644 --- a/src/ui/public/filter_manager/lib/phrase.js +++ b/src/ui/public/filter_manager/lib/phrase.js @@ -3,8 +3,10 @@ export default function buildPhraseFilter(field, value, indexPattern) { let filter = { meta: { index: indexPattern.id} }; if (field.scripted) { + // painless expects params.value while groovy and expression languages expect value. + const valueClause = field.lang === 'painless' ? 'params.value' : 'value'; _.set(filter, 'script.script', { - inline: '(' + field.script + ') == value', + inline: '(' + field.script + ') == ' + valueClause, lang: field.lang, params: { value: value diff --git a/src/ui/public/filter_manager/lib/range.js b/src/ui/public/filter_manager/lib/range.js index b04a4c46fa702..deec58b703199 100644 --- a/src/ui/public/filter_manager/lib/range.js +++ b/src/ui/public/filter_manager/lib/range.js @@ -33,15 +33,18 @@ export default function buildRangeFilter(field, params, indexPattern, formattedV lt: '<', }; - const script = _.map(params, function (val, key) { - return '(' + field.script + ')' + operators[key] + key; + const knownParams = _.pick(params, (val, key) => { return key in operators; }); + const script = _.map(knownParams, function (val, key) { + // painless expects params.[key] while groovy and expression languages expect [key] only. + const valuePrefix = field.lang === 'painless' ? 'params.' : ''; + return '(' + field.script + ')' + operators[key] + valuePrefix + key; }).join(' && '); - const value = _.map(params, function (val, key) { + const value = _.map(knownParams, function (val, key) { return operators[key] + field.format.convert(val); }).join(' '); - _.set(filter, 'script.script', { inline: script, params: params, lang: field.lang }); + _.set(filter, 'script.script', { inline: script, params: knownParams, lang: field.lang }); filter.script.script.params.value = value; filter.meta.field = field.name; } else {