From 8d432beb3dd902dbf0795494180b3353f7aec7e5 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Sat, 6 Sep 2014 03:24:03 +0200 Subject: [PATCH] Elasticsearch: adapt select() to use $where --- adminer/drivers/elastic.inc.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index b266a6bb..cb7fe1ef 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -126,17 +126,21 @@ if (isset($_GET["elastic"])) { $data["from"] = ($page * $limit); } } - foreach ((array) $_GET["where"] as $val) { - if ("$val[col]$val[val]" != "") { - $term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"])); - if ($val["op"] == "=") { + foreach ($where as $val) { + list($col,$op,$val) = explode(" ",$val,3); + if ($col == "_id") { + $data["query"]["ids"]["values"][] = $val; + } + elseif ($col . $val != "") { + $term = array("term" => array(($col != "" ? $col : "_all") => $val)); + if ($op == "=") { $data["query"]["filtered"]["filter"]["and"][] = $term; } else { $data["query"]["filtered"]["query"]["bool"]["must"][] = $term; } } } - if ($data["query"] && !$data["query"]["filtered"]["query"]) { + if ($data["query"] && !$data["query"]["filtered"]["query"] && !$data["query"]["ids"]) { $data["query"]["filtered"]["query"] = array("match_all" => array()); } $start = microtime(true); @@ -150,6 +154,9 @@ if (isset($_GET["elastic"])) { $return = array(); foreach ($search['hits']['hits'] as $hit) { $row = array(); + if ($select == array("*")) { + $row["_id"] = $hit["_id"]; + } $fields = $hit['_source']; if ($select != array("*")) { $fields = array(); @@ -292,6 +299,10 @@ if (isset($_GET["elastic"])) { "type" => $field["type"], "privileges" => array("insert" => 1, "select" => 1, "update" => 1), ); + if ($field["properties"]) { // only leaf fields can be edited + unset($return[$name]["privileges"]["insert"]); + unset($return[$name]["privileges"]["update"]); + } } } }