Using boolean fields in groovy script in elasticsearch - doc['field_name'].value not working Using boolean fields in groovy script in elasticsearch - doc['field_name'].value not working elasticsearch elasticsearch

Using boolean fields in groovy script in elasticsearch - doc['field_name'].value not working


I'm having the same issue on ElasticSearch v1.5.1: Boolean values in the document show up as characters in my script, T' for true and 'F' for false:

if ( doc['is_new'].value == 'T') {1} else {0}


I've just got it!

First, it works only with _source.myField, not with doc['myField'].value.I think there's a bug there because the toBoolean() method should return a boolean depending on the actual value, but it doesn't.

But I also needed to declare the mapping of the field explicitly as boolean and not_analyzed.

I hope it helps!