summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/olivere/elastic/msearch.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/olivere/elastic/msearch.go')
-rw-r--r--vendor/github.com/olivere/elastic/msearch.go39
1 files changed, 27 insertions, 12 deletions
diff --git a/vendor/github.com/olivere/elastic/msearch.go b/vendor/github.com/olivere/elastic/msearch.go
index ed54d3c2f..c1a589a97 100644
--- a/vendor/github.com/olivere/elastic/msearch.go
+++ b/vendor/github.com/olivere/elastic/msearch.go
@@ -14,19 +14,17 @@ import (
// MultiSearch executes one or more searches in one roundtrip.
type MultiSearchService struct {
- client *Client
- requests []*SearchRequest
- indices []string
- pretty bool
- routing string
- preference string
+ client *Client
+ requests []*SearchRequest
+ indices []string
+ pretty bool
+ maxConcurrentRequests *int
+ preFilterShardSize *int
}
func NewMultiSearchService(client *Client) *MultiSearchService {
builder := &MultiSearchService{
- client: client,
- requests: make([]*SearchRequest, 0),
- indices: make([]string, 0),
+ client: client,
}
return builder
}
@@ -46,6 +44,16 @@ func (s *MultiSearchService) Pretty(pretty bool) *MultiSearchService {
return s
}
+func (s *MultiSearchService) MaxConcurrentSearches(max int) *MultiSearchService {
+ s.maxConcurrentRequests = &max
+ return s
+}
+
+func (s *MultiSearchService) PreFilterShardSize(size int) *MultiSearchService {
+ s.preFilterShardSize = &size
+ return s
+}
+
func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error) {
// Build url
path := "/_msearch"
@@ -55,6 +63,12 @@ func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error)
if s.pretty {
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
}
+ if v := s.maxConcurrentRequests; v != nil {
+ params.Set("max_concurrent_searches", fmt.Sprintf("%v", *v))
+ }
+ if v := s.preFilterShardSize; v != nil {
+ params.Set("pre_filter_shard_size", fmt.Sprintf("%v", *v))
+ }
// Set body
var lines []string
@@ -68,14 +82,14 @@ func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error)
if err != nil {
return nil, err
}
- body, err := json.Marshal(sr.Body())
+ body, err := sr.Body()
if err != nil {
return nil, err
}
lines = append(lines, string(header))
- lines = append(lines, string(body))
+ lines = append(lines, body)
}
- body := strings.Join(lines, "\n") + "\n" // Don't forget trailing \n
+ body := strings.Join(lines, "\n") + "\n" // add trailing \n
// Get response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
@@ -96,6 +110,7 @@ func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error)
return ret, nil
}
+// MultiSearchResult is the outcome of running a multi-search operation.
type MultiSearchResult struct {
Responses []*SearchResult `json:"responses,omitempty"`
}