Merge pull request #8714 from elastic/jasper/backport/8691/5.0

[backport] PR #8691 to 5.0
This commit is contained in:
Stacey Gammon 2016-10-17 15:39:00 -04:00 committed by GitHub
commit d981b231e9

View file

@ -5,11 +5,23 @@ export default function buildPhraseFilter(field, value, indexPattern) {
if (field.scripted) {
// painless expects params.value while groovy and expression languages expect value.
const valueClause = field.lang === 'painless' ? 'params.value' : 'value';
// See https://github.com/elastic/elasticsearch/issues/20941 and https://github.com/elastic/kibana/issues/8677
// for the reason behind this change. ES doesn't handle boolean types very well, so they come
// back as strings.
let convertedValue = value;
if (typeof value !== 'boolean' && field.type === 'boolean') {
if (value !== 'true' && value !== 'false') {
throw new Error('Boolean scripted fields must return true or false');
}
convertedValue = value === 'true' ? true : false;
}
_.set(filter, 'script.script', {
inline: '(' + field.script + ') == ' + valueClause,
lang: field.lang,
params: {
value: value
value: convertedValue
}
});
filter.meta.field = field.name;