---------

**Commit 1:**
Ensure boolean scripted field values are of boolean type

they come back from the server as ‘true’ currently.  Hopefully that
will be fixed in the future, so to future-proof this I am only
converting when the value is not of type boolean.

Fixes #8677

Need to convert both number and bool strings to their respective types.

Throw an error for unexpected types/values.

* Original sha: 7b8ff74513
* Authored by Stacey Gammon <gammon@elastic.co> on 2016-10-14T19:50:23Z
This commit is contained in:
Elastic Jasper 2016-10-17 15:21:57 -04:00
parent c60a481602
commit 20053f4e68

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;