diff --git a/search/opensearch_types.go b/search/opensearch_types.go index 673ab096f00fa54e2cb605663a87e9fac61c9fe0..a8d1880021ab6bb5778e6fc9cf38379c6ca12822 100644 --- a/search/opensearch_types.go +++ b/search/opensearch_types.go @@ -34,10 +34,10 @@ type MappingKeyword struct { } type SearchRequestBody struct { - Size int64 `json:"size,omitempty"` + Sort []map[string]string `json:"sort,omitempty"` // order and order_by + Size int64 `json:"size,omitempty"` // limit + From int64 `json:"from,omitempty"` // offset Query Query `json:"query"` - Sort []map[string]string `json:"sort,omitempty"` - From int64 `json:"from,omitempty"` } type Query struct { diff --git a/search/time_series.go b/search/time_series.go index 54d56b54e033f7893b558e5e04a9bc7027228f46..e3542d00ff8dca62e5b6c8e6333c7ce19a68c179 100644 --- a/search/time_series.go +++ b/search/time_series.go @@ -398,7 +398,7 @@ type IndexSettings struct { //Search //Return: // docs will be a slice of the TimeSeries data type -func (ts *timeSeries) Search(query Query, sortQuery []map[string]string, limit int64, offset int64) (docs map[string]interface{}, totalCount int, err error) { +func (ts *timeSeries) Search(query Query, sort []map[string]string, limit int64, offset int64) (docs map[string]interface{}, totalCount int, err error) { if ts == nil { return nil, 0, errors.Errorf("time series == nil") } @@ -418,10 +418,10 @@ func (ts *timeSeries) Search(query Query, sortQuery []map[string]string, limit i // } // } body := SearchRequestBody{ + Sort: sort, Size: limit, - Query: query, - Sort: sortQuery, From: offset, + Query: query, } jsonBody, _ := json.Marshal(body) @@ -471,6 +471,9 @@ func (ts *timeSeries) Search(query Query, sortQuery []map[string]string, limit i } docs = map[string]interface{}{} + if !hits.IsValid() { + return + } for i := 0; i < hits.Len(); i++ { hit := hits.Index(i) index := hit.Field(0).Interface().(string) // HitDoc.Index