feat: add support for search after

This commit is contained in:
Hardy
2021-03-02 11:51:41 +08:00
parent 8661572bd5
commit 09acfd6a3d
3 changed files with 27 additions and 15 deletions
+20 -11
View File
@@ -15,16 +15,17 @@ import (
// Not all features of the search API are currently supported, but a request can
// currently include a query, aggregations, and more.
type SearchRequest struct {
aggs []Aggregation
explain *bool
from *uint64
highlight Mappable
postFilter Mappable
query Mappable
size *uint64
sort Sort
source Source
timeout *time.Duration
aggs []Aggregation
explain *bool
from *uint64
highlight Mappable
searchAfter []string
postFilter Mappable
query Mappable
size *uint64
sort Sort
source Source
timeout *time.Duration
}
// Search creates a new SearchRequest object, to be filled via method chaining.
@@ -74,6 +75,12 @@ func (req *SearchRequest) Sort(name string, order Order) *SearchRequest {
return req
}
// SearchAfter retrieve the sorted result
func (req *SearchRequest) SearchAfter(s ...string) *SearchRequest {
req.searchAfter = append(req.searchAfter, s...)
return req
}
// Explain sets whether the ElasticSearch API should return an explanation for
// how each hit's score was calculated.
func (req *SearchRequest) Explain(b bool) *SearchRequest {
@@ -105,7 +112,6 @@ func (req *SearchRequest) Highlight(highlight Mappable) *SearchRequest {
return req
}
// Map implements the Mappable interface. It converts the request to into a
// nested map[string]interface{}, as expected by the go-elasticsearch library.
func (req *SearchRequest) Map() map[string]interface{} {
@@ -142,6 +148,9 @@ func (req *SearchRequest) Map() map[string]interface{} {
if req.highlight != nil {
m["highlight"] = req.highlight.Map()
}
if req.searchAfter != nil {
m["search_after"] = req.searchAfter
}
source := req.source.Map()
if len(source) > 0 {