]> git.joonet.de Git - adminer.git/commitdiff
Fix displaying type mapping for Elasticsearch >= 6.0
authorPeter Knut <peter@pematon.com>
Wed, 28 Oct 2020 13:06:27 +0000 (14:06 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sun, 7 Feb 2021 12:24:03 +0000 (13:24 +0100)
Earlier versions of Elasticsearch (<= 5) supported multiple types per index. That meant that you could have different data mappings for each type. With Elasticsearch 6, this was removed and you can only have single mapping type.

adminer/drivers/elastic.inc.php
changes.txt

index f2abfad7d3e83c121cddb793af5d48d50994821b..75a19f16e783cf22e34b36b17fded354f3d2b86f 100644 (file)
@@ -7,7 +7,7 @@ if (isset($_GET["elastic"])) {
 
        if (function_exists('json_decode') && ini_bool('allow_url_fopen')) {
                class Min_DB {
-                       var $extension = "JSON", $server_info, $errno, $error, $_url;
+                       var $extension = "JSON", $server_info, $errno, $error, $_url, $_db;
 
                        /** Performs query
                         * @param string
@@ -284,6 +284,11 @@ if (isset($_GET["elastic"])) {
 
        function tables_list() {
                global $connection;
+
+               if (min_version(6)) {
+                       return array('_doc' => 'table');
+               }
+
                $return = $connection->query('_mapping');
                if ($return) {
                        $return = array_fill_keys(array_keys($return[$connection->_db]["mappings"]), 'table');
@@ -339,25 +344,35 @@ if (isset($_GET["elastic"])) {
 
        function fields($table) {
                global $connection;
-               $result = $connection->query("$table/_mapping");
-               $return = array();
-               if ($result) {
-                       $mappings = $result[$table]['properties'];
-                       if (!$mappings) {
-                               $mappings = $result[$connection->_db]['mappings'][$table]['properties'];
+
+               $mappings = array();
+               if (min_version(6)) {
+                       $result = $connection->query("_mapping");
+                       if ($result) {
+                               $mappings = $result[$connection->_db]['mappings']['properties'];
                        }
-                       if ($mappings) {
-                               foreach ($mappings as $name => $field) {
-                                       $return[$name] = array(
-                                               "field" => $name,
-                                               "full_type" => $field["type"],
-                                               "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"]);
-                                       }
+               } else {
+                       $result = $connection->query("$table/_mapping");
+                       if ($result) {
+                               $mappings = $result[$table]['properties'];
+                               if (!$mappings) {
+                                       $mappings = $result[$connection->_db]['mappings'][$table]['properties'];
+                               }
+                       }
+               }
+
+               $return = array();
+               if ($mappings) {
+                       foreach ($mappings as $name => $field) {
+                               $return[$name] = array(
+                                       "field" => $name,
+                                       "full_type" => $field["type"],
+                                       "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"]);
                                }
                        }
                }
index e02b19e59c8e6f6e4dc07168a205ad89510077fc..2ecf886f2f3945dbc5736da1842d3b6a1ee66d7c 100644 (file)
@@ -17,6 +17,7 @@ PostgreSQL 10: Support partitioned tables (PR #396)
 PostgreSQL 11: Create PRIMARY KEY for auto increment columns
 SQLite: Set busy_timeout to 500
 MS SQL: Don't truncate comments to 30 chars (PR #376)
+Elasticsearch 6: Fix displaying type mapping (PR #402)
 MongoDB: Fix password-less check in the mongo extension (PR #405)
 Editor: Cast to string when searching (bug #325)
 Re-enable PHP warnings (regression from 4.7.8)