]> git.joonet.de Git - adminer.git/commitdiff
Elastic: Properly display sparse result rows
authorChristian Weiske <cweiske@cweiske.de>
Fri, 28 Feb 2025 11:45:03 +0000 (12:45 +0100)
committerJakub Vrána <jakub@vrana.cz>
Mon, 10 Mar 2025 20:14:54 +0000 (21:14 +0100)
Result records in Elasticsearch do not always have all columns
that are defined in an index.
This often happens when multiple document types are stored in the same index.

The first row has columns ["_id", "html", "url"], while the second
misses the "html" column: ["_id", "url"].

Adminer expects that all result rows include all columns.
This leads to the problem that the "url" value in the 2nd example row
was rendered in the "html" column.

This patch fixes this problem by fetching the actual column list first
when all fields are to be shown, and using that field list
as base for all rows.

plugins/drivers/elastic.php

index 29d4665178c6317ecb8771d2723826081a9bf237..a11dd64f72dac0b3336c13f75ffc6f902d4ad609 100644 (file)
@@ -205,6 +205,9 @@ if (isset($_GET["elastic"])) {
                        if (empty($search)) {
                                return false;
                        }
+                       if ($select == array("*")) {
+                               $tableFields = array_keys(fields($table));
+                       }
 
                        $return = array();
                        foreach ($search["hits"]["hits"] as $hit) {
@@ -219,7 +222,9 @@ if (isset($_GET["elastic"])) {
                                                $fields[$key] = $key == "_id" ? $hit["_id"] : $hit["_source"][$key];
                                        }
                                } else {
-                                       $fields = $hit["_source"];
+                                       foreach ($tableFields as $key) {
+                                               $fields[$key] = $key == "_id" ? $hit["_id"] : $hit["_source"][$key];
+                                       }
                                }
                                foreach ($fields as $key => $val) {
                                        $row[$key] = (is_array($val) ? json_encode($val) : $val);