Bug 21146

Summary: Elasticsearch 5.6+ doesn't consider '0' a valid boolean
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Searching - ElasticsearchAssignee: Bugs List <koha-bugs>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P5 - low CC: alex.arnaud, ere.maijala, joonas.kylmala, nick
Version: Main   
Hardware: All   
OS: All   
URL: https://discuss.elastic.co/t/perl-and-new-boolean-restriction-in-es5/94529
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 20196    

Description Tomás Cohen Arazi (tcohen) 2018-08-02 10:14:34 UTC
To reproduce:
- Set SearchEngine=Zebra
- Run:
  $ kshell
 k$ prove prove t/db_dependent/Circulation/Returns.t
=> SUCCESS: Tests pass!
- Set SearchEngine=Elasticsearch
- Run:
 k$ prove prove t/db_dependent/Circulation/Returns.t
=> FAIL: Things explode because '0' is not a valid boolean for Elasticsearch (legacy fallback in past versions).
Comment 1 Tomás Cohen Arazi (tcohen) 2018-08-02 13:38:49 UTC
Maybe:

diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm
index 9c114fb060..c7081ee559 100644
--- a/Koha/SearchEngine/Elasticsearch.pm
+++ b/Koha/SearchEngine/Elasticsearch.pm
@@ -308,7 +308,11 @@ sub get_fixer_rules {
                 # boolean gets special handling, basically if it doesn't exist,
                 # it's added and set to false. Otherwise we can't query it.
                 push @rules,
-                  "unless exists('$name') add_field('$name', 0) end";
+                  "if is_true('$name')
+                     add_field('$name', 'true')
+                   else
+                     add_field('$name', 'false')
+                   end";
             }
             if ($type eq 'sum' ) {
                 push @rules, "sum('$name')";
Comment 2 Joonas Kylmälä 2018-10-19 12:41:02 UTC
if accepted, Bug #19893 will fix this.
Comment 3 Nick Clemens (kidclamp) 2019-02-14 15:35:27 UTC

*** This bug has been marked as a duplicate of bug 19893 ***