diff --git a/go.mod b/go.mod index d17acbf..7f6ca00 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/aquasecurity/esquery +module github.com/okdanta/esquery go 1.13 diff --git a/search.go b/search.go index 5c661a2..cb406da 100644 --- a/search.go +++ b/search.go @@ -25,8 +25,8 @@ type SearchRequest struct { size *uint64 sort Sort source Source + collapse map[string]interface{} timeout *time.Duration - } // Search creates a new SearchRequest object, to be filled via method chaining. @@ -40,6 +40,14 @@ func (req *SearchRequest) Query(q Mappable) *SearchRequest { return req } +// Collapse sets one field to collapse for the request. +func (req *SearchRequest) Collapse(field string) *SearchRequest { + req.collapse = map[string]interface{}{ + "field": field, + } + return req +} + // Aggs sets one or more aggregations for the request. func (req *SearchRequest) Aggs(aggs ...Aggregation) *SearchRequest { req.aggs = append(req.aggs, aggs...) @@ -113,8 +121,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{} { @@ -155,6 +161,9 @@ func (req *SearchRequest) Map() map[string]interface{} { m["search_after"] = req.searchAfter } + if req.collapse != nil { + m["collapse"] = req.collapse + } source := req.source.Map() if len(source) > 0 {