From 5a5e25f3dadc16958a733a16d6451cdfe1ad0ea2 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Thu, 23 Nov 2023 16:07:32 +0100 Subject: [PATCH] Issue #22: enable sort on _doc --- pkg/quickwit/data_query.go | 5 ++--- pkg/quickwit/response_parser.go | 1 + pkg/quickwit/response_parser_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/quickwit/data_query.go b/pkg/quickwit/data_query.go index 96efbf8..0bfb0be 100644 --- a/pkg/quickwit/data_query.go +++ b/pkg/quickwit/data_query.go @@ -335,8 +335,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa sort = es.SortOrderAsc } b.Sort(sort, defaultTimeField, "boolean") - // FIXME: check if sort by _doc is needed. - // b.Sort(sort, "_doc", "") + b.Sort(sort, "_doc", "") b.Size(stringToIntWithDefaultValue(metric.Settings.Get("limit").MustString(), defaultSize)) // TODO when hightlight is supported in quickwit // b.AddHighlight() @@ -352,7 +351,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa func processDocumentQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defaultTimeField string) { metric := q.Metrics[0] b.Sort(es.SortOrderDesc, defaultTimeField, "boolean") - // b.Sort(es.SortOrderDesc, "_doc", "") + b.Sort(es.SortOrderDesc, "_doc", "") // Note: not supported in Quickwit // b.AddDocValueField(defaultTimeField) b.Size(stringToIntWithDefaultValue(metric.Settings.Get("size").MustString(), defaultSize)) diff --git a/pkg/quickwit/response_parser.go b/pkg/quickwit/response_parser.go index 990ca23..818d0bc 100644 --- a/pkg/quickwit/response_parser.go +++ b/pkg/quickwit/response_parser.go @@ -108,6 +108,7 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields doc := map[string]interface{}{ "_source": flattened, + "sort": hit["sort"], } for k, v := range flattened { diff --git a/pkg/quickwit/response_parser_test.go b/pkg/quickwit/response_parser_test.go index 27d7658..e7f111d 100644 --- a/pkg/quickwit/response_parser_test.go +++ b/pkg/quickwit/response_parser_test.go @@ -304,7 +304,7 @@ func TestProcessLogsResponse(t *testing.T) { require.Len(t, dataframes, 1) frame := dataframes[0] - require.Equal(t, 11, len(frame.Fields)) + require.Equal(t, 12, len(frame.Fields)) // Fields have the correct length require.Equal(t, 2, frame.Fields[0].Len()) // First field is timeField @@ -324,7 +324,7 @@ func TestProcessLogsResponse(t *testing.T) { require.Equal(t, "nested.field.double_nested", frame.Fields[8].Name) require.Equal(t, data.FieldTypeNullableString, frame.Fields[8].Type()) // Correctly detects type even if first value is null - require.Equal(t, data.FieldTypeNullableString, frame.Fields[10].Type()) + require.Equal(t, data.FieldTypeNullableJSON, frame.Fields[10].Type()) }) }