Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Take into account raw_data query's Size and Order #210

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/opensearch/client/search_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ func (b *SearchRequestBuilder) Size(size int) *SearchRequestBuilder {
return b
}

// SortDesc adds a sort to the search request
func (b *SearchRequestBuilder) SortDesc(field, unmappedType string) *SearchRequestBuilder {
const defaultOrder = "desc"

// Sort adds a sort to the search request
func (b *SearchRequestBuilder) Sort(order, field, unmappedType string) *SearchRequestBuilder {
if order != "desc" && order != "asc" {
order = defaultOrder
}
props := map[string]string{
"order": "desc",
"order": order,
}

if unmappedType != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/opensearch/client/search_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSearchRequest(t *testing.T) {

Convey("When adding size, sort, filters", func() {
b.Size(200)
b.SortDesc(timeField, "boolean")
b.Sort("desc", timeField, "boolean")
filters := b.Query().Bool().Filter()
filters.AddDateRangeFilter(timeField, DateFormatEpochMS, 10, 5)
filters.AddQueryStringFilter("test", true)
Expand Down
14 changes: 11 additions & 3 deletions pkg/opensearch/lucene_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ func (h *luceneHandler) processQuery(q *Query) error {
return nil
}

const defaultSize = 500

func processRawDataQuery(q *Query, b *es.SearchRequestBuilder, defaultTimeField string) {
metric := q.Metrics[0]
b.SortDesc(defaultTimeField, "boolean")
b.SortDesc("_doc", "")
order := metric.Settings.Get("order").MustString()
b.Sort(order, defaultTimeField, "boolean")
b.Sort(order, "_doc", "")
b.AddTimeFieldWithStandardizedFormat(defaultTimeField)
b.Size(metric.Settings.Get("size").MustInt(500))
sizeString := metric.Settings.Get("size").MustString()
size, err := strconv.Atoi(sizeString)
if err != nil {
size = defaultSize
}
b.Size(size)
}

func processTimeSeriesQuery(q *Query, b *es.SearchRequestBuilder, fromMs int64, toMs int64) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/opensearch/time_series_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Test_raw_data(t *testing.T) {
_, err := executeTsdbQuery(c, `{
"timeField": "@timestamp",
"bucketAggs": [],
"metrics": [{ "id": "1", "type": "raw_data", "settings": {"size": 1337 } }]
"metrics": [{ "id": "1", "type": "raw_data", "settings": {"size": "1337" } }]
}`, from, to, 15*time.Second)
require.NoError(t, err)

Expand Down