1
0
Эх сурвалжийг харах

TSDB: Fix error when sorting by _tsid (#81583)

The SearchSortValues allows only instances of Boolean, String and Number fields so that it presents the value of the sort fields in the results. This results in an error when sorting by _tsid
Christos Soulios 3 жил өмнө
parent
commit
a0c1027174

+ 18 - 0
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/40_search.yml

@@ -378,3 +378,21 @@ ids query:
   - match: {hits.hits.0.fields.k8s\.pod\.network\.tx: [2001828691]}
   - match: {hits.hits.1._id: "u3"}
   - match: {hits.hits.1.fields.k8s\.pod\.network\.tx: [2001848691]}
+
+---
+sort by tsid:
+  - skip:
+      version: " - 8.0.99"
+      reason: _tsid introduced in 8.1.0
+
+  - do:
+      search:
+        index: test
+        body:
+          sort:   [ "_tsid", "@timestamp" ]
+
+  - match: {hits.total.value: 8}
+  - match: {hits.hits.0.sort: [{ "k8s.pod.uid" : "947e4ced-1786-4e53-9e0c-5c447e959507", "metricset" : "pod"}, 1619635804467]}
+  - match: {hits.hits.1.sort: [{ "k8s.pod.uid" : "947e4ced-1786-4e53-9e0c-5c447e959507", "metricset" : "pod"}, 1619635824467]}
+  - match: {hits.hits.4.sort: [{ "k8s.pod.uid" : "df3145b3-0563-4d3b-a0f7-897eb2876ea9", "metricset" : "pod"}, 1619635803142]}
+  - match: {hits.hits.7.sort: [{ "k8s.pod.uid" : "df3145b3-0563-4d3b-a0f7-897eb2876ea9", "metricset" : "pod"}, 1619635863142]}

+ 3 - 1
server/src/main/java/org/elasticsearch/search/SearchSortValues.java

@@ -20,6 +20,7 @@ import org.elasticsearch.xcontent.XContentParser;
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Map;
 import java.util.Objects;
 
 public class SearchSortValues implements ToXContentFragment, Writeable {
@@ -45,7 +46,8 @@ public class SearchSortValues implements ToXContentFragment, Writeable {
         this.formattedSortValues = new Object[rawSortValues.length];
         for (int i = 0; i < rawSortValues.length; ++i) {
             final Object v = sortValueFormats[i].formatSortValue(rawSortValues[i]);
-            assert v == null || v instanceof String || v instanceof Number || v instanceof Boolean : v + " was not formatted";
+            assert v == null || v instanceof String || v instanceof Number || v instanceof Boolean || v instanceof Map
+                : v + " was not formatted";
             formattedSortValues[i] = v;
         }
     }