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.
This commit is contained in:
Peter Knut 2020-10-28 14:06:27 +01:00 committed by Jakub Vrana
parent 52defd6f19
commit 922e1d96b0
2 changed files with 35 additions and 19 deletions

View 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"]);
}
}
}

View 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)