---------

**Commit 1:**
Fix our request to ES for filtering on scripted fields

Need to use params.value instead of value.

Fixes #8404

Add params prefix in another spot for painless scripted fields

Fix date histogram with scripted fields

Remove format: epoch_millis so the script compiles.  I am not 100%
confident of the side affect from this (it’s used for non-scripted
fields, but I’m not sure where I would put it for scripted fields, or
if it’s needed).  At any rate, it appears that formatting settings for
scripted fields is still being honored, even after removing it from
params.

* Original sha: 7cdb74d6c9
* Authored by Stacey Gammon <gammon@elastic.co> on 2016-10-12T14:54:23Z
This commit is contained in:
Elastic Jasper 2016-10-13 17:43:35 -04:00
parent aad5e9a5fe
commit 668bd10132
4 changed files with 16 additions and 8 deletions

View file

@ -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}
}

View file

@ -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;
};

View file

@ -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

View file

@ -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 {