]> git.joonet.de Git - adminer.git/commitdiff
Elasticsearch: adapt select() to use $where
authorGargaj <gargaj@conspiracy.hu>
Sat, 6 Sep 2014 01:24:03 +0000 (03:24 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 11 Sep 2014 15:44:05 +0000 (08:44 -0700)
adminer/drivers/elastic.inc.php

index b266a6bb65eb7e255712e1011df16de5796ec9c5..cb7fe1ef5ab5db2d03a54c6aef9eb5780a83c2af 100644 (file)
@@ -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"]);
+                                       }
                                }
                        }
                }