diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef8f4e77..290c1f86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
## Adminer dev
Export: Fix tar (regression from 5.0.3)
+Elasticsearch: Make it work with Elasticsearch 8
CSS: Invert icons in dark mode
## Adminer 5.1.0 (released 2025-03-24)
diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php
index 58db6475..947d0775 100644
--- a/adminer/include/functions.inc.php
+++ b/adminer/include/functions.inc.php
@@ -438,8 +438,10 @@ function redirect(?string $location, string $message = null): void {
}
}
-/** Execute query and redirect if successful */
-function query_redirect(string $query, string $location, string $message, bool $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
+/** Execute query and redirect if successful
+* @param bool $redirect
+*/
+function query_redirect(string $query, string $location, string $message, $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
global $connection, $error, $adminer;
if ($execute) {
$start = microtime(true);
diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php
index 859256c7..b1ed0f84 100644
--- a/plugins/drivers/elastic.php
+++ b/plugins/drivers/elastic.php
@@ -16,14 +16,17 @@ if (isset($_GET["elastic"])) {
* @return array|false
*/
function rootQuery(string $path, ?array $content = null, string $method = 'GET') {
- $file = @file_get_contents("$this->url/" . ltrim($path, '/'), false, stream_context_create(array('http' => array(
- 'method' => $method,
- 'content' => $content !== null ? json_encode($content) : null,
- 'header' => $content !== null ? 'Content-Type: application/json' : array(),
- 'ignore_errors' => 1,
- 'follow_location' => 0,
- 'max_redirects' => 0,
- ))));
+ $file = @file_get_contents("$this->url/" . ltrim($path, '/'), false, stream_context_create(array(
+ //~ 'ssl' => array('verify_peer' => false),
+ 'http' => array(
+ 'method' => $method,
+ 'content' => $content !== null ? json_encode($content) : null,
+ 'header' => $content !== null ? 'Content-Type: application/json' : array(),
+ 'ignore_errors' => 1,
+ 'follow_location' => 0,
+ 'max_redirects' => 0,
+ ),
+ )));
if ($file === false) {
$this->error = lang('Invalid server or credentials.');
@@ -219,9 +222,9 @@ if (isset($_GET["elastic"])) {
$parts = preg_split('~ *= *~', $queryWhere);
if (count($parts) == 2) {
$id = trim($parts[1]);
- $query = "$type/$id";
-
- return $this->conn->rootQuery($query, $record, 'POST');
+ $query = "$table/_update/$id";
+ $this->conn->affected_rows = 0;
+ return $this->conn->rootQuery($query, array('doc' => $set), 'POST');
}
return false;
@@ -518,18 +521,24 @@ if (isset($_GET["elastic"])) {
function alter_table(string $table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$properties = array();
foreach ($fields as $f) {
- $field_name = trim($f[1][0]);
- $field_type = trim($f[1][1] ?: "text");
- $properties[$field_name] = array(
- 'type' => $field_type
- );
+ if ($f[1]) {
+ $field_name = trim($f[1][0]);
+ $field_type = trim($f[1][1] ?: "text");
+ $properties[$field_name] = array(
+ 'type' => $field_type
+ );
+ }
}
if (!empty($properties)) {
$properties = array('properties' => $properties);
}
- return connection()->rootQuery("_mapping/$name", $properties, 'PUT');
+ if ($table != '') {
+ return connection()->rootQuery("$name/_mapping", $properties, 'POST');
+ } else {
+ return connection()->rootQuery($name, array('mappings' => $properties), 'PUT');
+ }
}
/** Drop types
diff --git a/tests/elastic.html b/tests/elastic.html
new file mode 100644
index 00000000..f0cf3937
--- /dev/null
+++ b/tests/elastic.html
@@ -0,0 +1,109 @@
+
+
+
+
+
+ Katalon Elasticsearch
+
+
+
+
+Login |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200 | |
+select | name=lang | label=English |
+clickAndWait | css=#lang > input[type="submit"] | |
+type | id=username | ODBC |
+type | name=auth[password] | ODBC12 |
+clickAndWait | //input[@value='Login'] | |
+verifyTextPresent | JSON | |
+
+
+
+Create table |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic | |
+clickAndWait | link=Create table | |
+type | name | interprets |
+type | fields[1][field] | name |
+select | fields[1][type] | label=text |
+clickAndWait | //input[@value='Save'] | |
+verifyTextPresent | Table has been created. | |
+
+
+
+Alter table |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&table=interprets | |
+clickAndWait | link=Alter table | |
+click | add[2] | |
+type | fields[3][field] | albums |
+select | fields[3][type] | label=integer |
+clickAndWait | //input[@value='Save'] | |
+verifyTextPresent | Table has been altered. | |
+
+
+
+Insert |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&edit=interprets | |
+type | fields[name] | Michael Jackson |
+clickAndWait | //input[@value='Save'] | |
+verifyTextPresent | has been inserted. | |
+
+
+
+Select |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&select=interprets | |
+click | link=Search | |
+select | name=where[0][col] | label=name |
+select | name=where[0][op] | label=should |
+type | name=where[0][val] | Jackson |
+click | link=Sort | |
+select | name=order[0] | label=albums |
+clickAndWait | xpath=//input[@value='Select'] | |
+verifyTextPresent | 1 row | |
+
+
+
+Update |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&select=interprets | |
+clickAndWait | link=edit | |
+type | fields[albums] | 1 |
+clickAndWait | //input[@value='Save'] | |
+verifyTextPresent | Item has been updated. | |
+
+
+
+Delete |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&select=interprets | |
+click | name=check[] | |
+waitForChecked | name=check[] | |
+chooseOkOnNextConfirmation | Are you sure? | |
+click | delete | |
+verifyTextPresent | 1 item has been affected. | |
+
+
+
+Drop |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC&db=elastic&create=interprets | |
+chooseOkOnNextConfirmation | Drop interprets? | |
+click | name=drop | |
+verifyTextPresent | No tables. | |
+
+
+
+Logout |
+
+open | /adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&username=ODBC | |
+clickAndWait | logout | |
+verifyTextPresent | Logout successful. | |
+open | /coverage.php | |
+
+
+
+
diff --git a/tests/generate-pdo.php b/tests/generate-pdo.php
index 5811301c..4f65d308 100755
--- a/tests/generate-pdo.php
+++ b/tests/generate-pdo.php
@@ -5,7 +5,7 @@
chdir(__DIR__);
foreach (glob("*.html") as $filename) {
- if (!preg_match('~^pdo-~', $filename)) {
+ if (!preg_match('~^pdo-|elastic~', $filename)) {
$file = file_get_contents($filename);
$file = preg_replace_callback('~/(adminer(/sqlite)?|editor/example)\.php(\??)~', function ($match) {
return "/$match[1].php?ext=pdo" . ($match[3] ? "&" : "");