search-collapse #6

Merged
maxim.yanchuk merged 17 commits from search-collapse into master 2023-11-01 21:11:52 +00:00
2 changed files with 13 additions and 4 deletions
Showing only changes of commit 4951f7774d - Show all commits

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/aquasecurity/esquery module github.com/okdanta/esquery
go 1.13 go 1.13

View File

@ -25,8 +25,8 @@ type SearchRequest struct {
size *uint64 size *uint64
sort Sort sort Sort
source Source source Source
collapse map[string]interface{}
timeout *time.Duration timeout *time.Duration
} }
// Search creates a new SearchRequest object, to be filled via method chaining. // 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 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. // Aggs sets one or more aggregations for the request.
func (req *SearchRequest) Aggs(aggs ...Aggregation) *SearchRequest { func (req *SearchRequest) Aggs(aggs ...Aggregation) *SearchRequest {
req.aggs = append(req.aggs, aggs...) req.aggs = append(req.aggs, aggs...)
@ -113,8 +121,6 @@ func (req *SearchRequest) Highlight(highlight Mappable) *SearchRequest {
return req return req
} }
// Map implements the Mappable interface. It converts the request to into a // Map implements the Mappable interface. It converts the request to into a
// nested map[string]interface{}, as expected by the go-elasticsearch library. // nested map[string]interface{}, as expected by the go-elasticsearch library.
func (req *SearchRequest) Map() map[string]interface{} { func (req *SearchRequest) Map() map[string]interface{} {
@ -155,6 +161,9 @@ func (req *SearchRequest) Map() map[string]interface{} {
m["search_after"] = req.searchAfter m["search_after"] = req.searchAfter
} }
if req.collapse != nil {
m["collapse"] = req.collapse
}
source := req.source.Map() source := req.source.Map()
if len(source) > 0 { if len(source) > 0 {