mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Update script syntax for scripted fields
Elasticsearch has removed the abbreviated script syntax that we were using in Kibana. This change updates all of Kibana's queries and filters to use the newer object syntax wherever scripted fields are valid. This commit also includes a change to pass the lang param when sorting by scripted field which fixes an error that was being thrown. Fixes: https://github.com/elastic/kibana/issues/7788 Fixes: https://github.com/elastic/kibana/issues/5676 Related: https://github.com/elastic/elasticsearch/pull/19387
This commit is contained in:
parent
0724220241
commit
ebb9cd2972
12 changed files with 48 additions and 36 deletions
|
@ -57,7 +57,7 @@ export default function FieldAggParamFactory(Private) {
|
|||
|
||||
if (field.scripted) {
|
||||
output.params.script = {
|
||||
script: field.script,
|
||||
inline: field.script,
|
||||
lang: field.lang,
|
||||
};
|
||||
} else {
|
||||
|
|
|
@ -58,7 +58,10 @@ describe('SearchSource#normalizeSortRequest', function () {
|
|||
sortState[fieldName] = direction;
|
||||
normalizedSort = {
|
||||
_script: {
|
||||
script: indexField.script,
|
||||
script: {
|
||||
inline: indexField.script,
|
||||
lang: indexField.lang
|
||||
},
|
||||
type: indexField.type,
|
||||
order: direction
|
||||
}
|
||||
|
|
|
@ -34,7 +34,10 @@ export default function normalizeSortRequest(config) {
|
|||
|
||||
sortField = '_script';
|
||||
sortValue = {
|
||||
script: indexField.script,
|
||||
script: {
|
||||
inline: indexField.script,
|
||||
lang: indexField.lang
|
||||
},
|
||||
type: indexField.type,
|
||||
order: direction
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ describe('Filter Bar Directive', function () {
|
|||
it('should return the key and value for matching filters', function (done) {
|
||||
let filter = {
|
||||
meta: { index: 'logstash-*', field: 'script number' },
|
||||
script: { script: 'doc["script number"].value * 5', params: { value: 35}}
|
||||
script: {script: { inline: 'doc["script number"].value * 5', params: { value: 35}}}
|
||||
};
|
||||
mapScript(filter).then(function (result) {
|
||||
expect(result).to.have.property('key', 'script number');
|
||||
|
@ -51,10 +51,12 @@ describe('Filter Bar Directive', function () {
|
|||
field: 'script number'
|
||||
},
|
||||
script: {
|
||||
params: {
|
||||
gte: 1000,
|
||||
lt: 2000,
|
||||
value: '>=1,000.00 <2,000.00'
|
||||
script: {
|
||||
params: {
|
||||
gte: 1000,
|
||||
lt: 2000,
|
||||
value: '>=1,000.00 <2,000.00'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ define(function () {
|
|||
if (filter.meta.formattedValue) {
|
||||
value = filter.meta.formattedValue;
|
||||
} else {
|
||||
value = filter.script.params.value;
|
||||
value = filter.script.script.params.value;
|
||||
value = field.format.convert(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -119,9 +119,11 @@ describe('Filter Manager', function () {
|
|||
checkAddFilters(1, [{
|
||||
meta: {index: 'myIndex', negate: false, field: 'scriptedField'},
|
||||
script: {
|
||||
script: '(' + scriptedField.script + ') == value',
|
||||
lang: scriptedField.lang,
|
||||
params: {value: 1}
|
||||
script: {
|
||||
inline: '(' + scriptedField.script + ') == value',
|
||||
lang: scriptedField.lang,
|
||||
params: {value: 1}
|
||||
}
|
||||
}
|
||||
}], 4);
|
||||
expect(appState.filters).to.have.length(3);
|
||||
|
|
|
@ -28,7 +28,7 @@ export default function (Private) {
|
|||
}
|
||||
|
||||
if (filter.script) {
|
||||
return filter.meta.field === fieldName && filter.script.params.value === value;
|
||||
return filter.meta.field === fieldName && filter.script.script.params.value === value;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -57,10 +57,12 @@ export default function (Private) {
|
|||
filter = {
|
||||
meta: { negate: negate, index: index, field: fieldName },
|
||||
script: {
|
||||
script: '(' + field.script + ') == value',
|
||||
lang: field.lang,
|
||||
params: {
|
||||
value: value
|
||||
script: {
|
||||
inline: '(' + field.script + ') == value',
|
||||
lang: field.lang,
|
||||
params: {
|
||||
value: value
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -32,13 +32,13 @@ describe('Filter Manager', function () {
|
|||
|
||||
it('should return a script filter when passed a scripted field', function () {
|
||||
expected.meta.field = 'script number';
|
||||
expected.script = {
|
||||
script: '(' + indexPattern.fields.byName['script number'].script + ') == value',
|
||||
_.set(expected, 'script.script', {
|
||||
inline: '(' + indexPattern.fields.byName['script number'].script + ') == value',
|
||||
lang: 'expression',
|
||||
params: {
|
||||
value: 5,
|
||||
}
|
||||
};
|
||||
});
|
||||
expect(fn(indexPattern.fields.byName['script number'], 5, indexPattern)).to.eql(expected);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,16 +30,16 @@ describe('Filter Manager', function () {
|
|||
|
||||
it('should return a script filter when passed a scripted field', function () {
|
||||
expected.meta.field = 'script number';
|
||||
expected.script = {
|
||||
_.set(expected, 'script.script', {
|
||||
lang: 'expression',
|
||||
script: '(' + indexPattern.fields.byName['script number'].script + ')>=gte && (' +
|
||||
indexPattern.fields.byName['script number'].script + ')<=lte',
|
||||
inline: '(' + indexPattern.fields.byName['script number'].script + ')>=gte && (' +
|
||||
indexPattern.fields.byName['script number'].script + ')<=lte',
|
||||
params: {
|
||||
value: '>=1 <=3',
|
||||
gte: 1,
|
||||
lte: 3
|
||||
}
|
||||
};
|
||||
});
|
||||
expect(fn(indexPattern.fields.byName['script number'], {gte: 1, lte: 3}, indexPattern)).to.eql(expected);
|
||||
});
|
||||
|
||||
|
@ -58,9 +58,9 @@ describe('Filter Manager', function () {
|
|||
params[key] = 5;
|
||||
let filter = fn(indexPattern.fields.byName['script number'], params, indexPattern);
|
||||
|
||||
expect(filter.script.script).to.be('(' + indexPattern.fields.byName['script number'].script + ')' + operator + key);
|
||||
expect(filter.script.params[key]).to.be(5);
|
||||
expect(filter.script.params.value).to.be(operator + 5);
|
||||
expect(filter.script.script.inline).to.be('(' + indexPattern.fields.byName['script number'].script + ')' + operator + key);
|
||||
expect(filter.script.script.params[key]).to.be(5);
|
||||
expect(filter.script.script.params.value).to.be(operator + 5);
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -77,16 +77,16 @@ describe('Filter Manager', function () {
|
|||
});
|
||||
|
||||
it('contain a param for the finite side', function () {
|
||||
expect(filter.script.params).to.have.property('gte', 0);
|
||||
expect(filter.script.script.params).to.have.property('gte', 0);
|
||||
});
|
||||
|
||||
it('does not contain a param for the infinite side', function () {
|
||||
expect(filter.script.params).not.to.have.property('lt');
|
||||
expect(filter.script.script.params).not.to.have.property('lt');
|
||||
});
|
||||
|
||||
it('does not contain a script condition for the infinite side', function () {
|
||||
const script = indexPattern.fields.byName['script number'].script;
|
||||
expect(filter.script.script).to.equal(`(${script})>=gte`);
|
||||
expect(filter.script.script.inline).to.equal(`(${script})>=gte`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,13 +3,13 @@ export default function buildPhraseFilter(field, value, indexPattern) {
|
|||
let filter = { meta: { index: indexPattern.id} };
|
||||
|
||||
if (field.scripted) {
|
||||
filter.script = {
|
||||
script: '(' + field.script + ') == value',
|
||||
_.set(filter, 'script.script', {
|
||||
inline: '(' + field.script + ') == value',
|
||||
lang: field.lang,
|
||||
params: {
|
||||
value: value
|
||||
}
|
||||
};
|
||||
});
|
||||
filter.meta.field = field.name;
|
||||
} else {
|
||||
filter.query = { match: {} };
|
||||
|
|
|
@ -41,8 +41,8 @@ export default function buildRangeFilter(field, params, indexPattern, formattedV
|
|||
return operators[key] + field.format.convert(val);
|
||||
}).join(' ');
|
||||
|
||||
filter.script = { script: script, params: params, lang: field.lang };
|
||||
filter.script.params.value = value;
|
||||
_.set(filter, 'script.script', { inline: script, params: params, lang: field.lang });
|
||||
filter.script.script.params.value = value;
|
||||
filter.meta.field = field.name;
|
||||
} else {
|
||||
filter.range = {};
|
||||
|
|
|
@ -11,7 +11,7 @@ export default function () {
|
|||
_.each(self.getScriptedFields(), function (field) {
|
||||
scriptFields[field.name] = {
|
||||
script: {
|
||||
script: field.script,
|
||||
inline: field.script,
|
||||
lang: field.lang
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue