]> git.joonet.de Git - adminer.git/commitdiff
Elastic: Fix text search on boolean fields
authorChristian Weiske <cweiske@cweiske.de>
Fri, 28 Feb 2025 13:32:23 +0000 (14:32 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 3 Mar 2025 09:40:38 +0000 (10:40 +0100)
When searching in all fields for a text value, an error was thrown
with ElasticSearch 7.17.23 when the index contains boolean fields:

> query_shard_exception: failed to create query:
> Can't parse boolean value [textvalue], expected [true] or [false]

This patch fixes that problem by skipping boolean fields when the
search word is not the string "true" or "false".

changes.txt
plugins/drivers/elastic.php

index db5ac9feba496f89b953c3bbbc9702f0690c73b1..92bfc160cb806fe300208711d540df64bf411b1d 100644 (file)
@@ -18,6 +18,7 @@ MS SQL: Remove support for MSSQL extension
 MS SQL: Add support for PDO_SQLSRV extension
 MS SQL: Link help from sys tables
 MongoDB: Remove support for deprecated extension mongo
+Elasticsearch: Fix text search on boolean fields
 
 Adminer 4.17.1 (released 2025-02-25):
 MySQL: Fix typo in the date type (regression from 4.17.0)
index b889fa2976d6190c59c898a7ed66d336dccf30ca..03f480b2370486212da121b07c7ae8d835cfe891 100644 (file)
@@ -143,13 +143,23 @@ if (isset($_GET["elastic"])) {
                                }
                        }
 
+                       $fields = null;
                        foreach ($where as $val) {
                                if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
                                        $parts = explode(" OR ", $matches[1]);
                                        $terms = array();
+
+                                       if ($fields === null) {
+                                               $fields = fields($table);
+                                       }
                                        foreach ($parts as $part) {
                                                list($col, $op, $val) = explode(" ", $part, 3);
                                                $term = array($col => $val);
+                                               if (isset($fields[$col]) && $fields[$col]['full_type'] == 'boolean'
+                                                       && $val !== 'true' && $val !== 'false'
+                                               ) {
+                                                       continue;
+                                               }
                                                if ($op == "=") {
                                                        $terms[] = array("term" => $term);
                                                } elseif (in_array($op, array("must", "should", "must_not"))) {