From 922e1d96b01b3e70a979a2d04e3993e62cee98bc Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Wed, 28 Oct 2020 14:06:27 +0100 Subject: [PATCH] Fix displaying type mapping for Elasticsearch >= 6.0 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 | 53 +++++++++++++++++++++------------ changes.txt | 1 + 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index f2abfad7..75a19f16 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -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"]); } } } diff --git a/changes.txt b/changes.txt index e02b19e5..2ecf886f 100644 --- a/changes.txt +++ b/changes.txt @@ -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)