From: Christian Weiske Date: Fri, 28 Feb 2025 13:32:23 +0000 (+0100) Subject: Elastic: Fix text search on boolean fields X-Git-Tag: v5.0.0~85 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=d5a17835ffa73f555cdcdb96d4b4bee1a714451a;p=adminer.git Elastic: Fix text search on boolean fields 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". --- diff --git a/changes.txt b/changes.txt index db5ac9fe..92bfc160 100644 --- a/changes.txt +++ b/changes.txt @@ -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) diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index b889fa29..03f480b2 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -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"))) {