From e8c9164a7797730985e6f7ba137bc19d965725ba Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Sun, 21 Mar 2021 20:40:43 +0100 Subject: [PATCH] Fix searching if "anywhere" field is selected - Allow to search only in fields with index. --- adminer/drivers/elastic.inc.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index 49d9eae4..22da0a4b 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -141,9 +141,25 @@ if (isset($_GET["elastic"])) { } } foreach ($where as $val) { - list($col, $op, $val) = explode(" ", $val, 3); - if ($col . $val != "") { - $term = array(($col != "" ? $col : "_all") => $val); + if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) { + $parts = explode(" OR ", $matches[1]); + $terms = array(); + foreach ($parts as $part) { + list($col, $op, $val) = explode(" ", $part, 3); + $term = array($col => $val); + if ($op == "=") { + $terms[] = array("term" => $term); + } elseif (in_array($op, array("must", "should", "must_not"))) { + $data["query"]["bool"][$op][]["match"] = $term; + } + } + + if (!empty($terms)) { + $data["query"]["bool"]["filter"][]["bool"]["should"] = $terms; + } + } else { + list($col, $op, $val) = explode(" ", $val, 3); + $term = array($col => $val); if ($op == "=") { $data["query"]["bool"]["filter"][] = array("term" => $term); } elseif (in_array($op, array("must", "should", "must_not"))) { @@ -377,6 +393,8 @@ if (isset($_GET["elastic"])) { ); foreach ($mappings as $name => $field) { + if (isset($field["index"]) && !$field["index"]) continue; + $return[$name] = array( "field" => $name, "full_type" => $field["type"],