Problem with boolean scripting values ​​with MVEL and Elasticsearch

I have a field mapping defined as

{"top_seller": {"Type": "logical"}}

In my query, I am trying to execute a custom evaluation query based on a boolean value. I pull my hair out. Every time I run a script, for example:

return if(doc['top_seller'].value==true) {10} else {0} 

Each individual document receives 10 pulses. Only 1% of my documents are set to TRUE. I tried without == true, with == 'true'. I tried trinity .. Document ['top_seller'] value == true 10: 0. I tried 1/0 instead of true / false.

I even did an experiment in which I created a new index and type with the help of one true and one false document. In a match_all request, they both get promoted as if they have a true value.

+4
source share
1 answer

Wow, on a whim, I looked at the settings of the main type for Boolean.

 The boolean type Maps to the JSON boolean type. It ends up storing within the index either T or F, with automatic translation to true and false respectively. 

Answer:

 doc['top_seller'].value == 'T' ? 10 : 0 

Edit: Starting with 5.2.x, was I finally able to use doc['top_seller'] ? 10 : 0 doc['top_seller'] ? 10 : 0 . https://www.elastic.co/guide/en/elasticsearch/reference/current/boolean.html

+20
source

All Articles