summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/client.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-04-16 05:37:14 -0700
committerJoram Wilander <jwawilander@gmail.com>2018-04-16 08:37:14 -0400
commit6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch)
tree3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/gopkg.in/olivere/elastic.v5/client.go
parentbf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff)
downloadchat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/client.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/client.go110
1 files changed, 90 insertions, 20 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/client.go b/vendor/gopkg.in/olivere/elastic.v5/client.go
index 165a30526..e709b0bf4 100644
--- a/vendor/gopkg.in/olivere/elastic.v5/client.go
+++ b/vendor/gopkg.in/olivere/elastic.v5/client.go
@@ -21,12 +21,12 @@ import (
"github.com/pkg/errors"
- "github.com/olivere/elastic/config"
+ "gopkg.in/olivere/elastic.v5/config"
)
const (
// Version is the current version of Elastic.
- Version = "6.1.7"
+ Version = "5.0.66"
// DefaultURL is the default endpoint of Elasticsearch on the local machine.
// It is used e.g. when initializing a new Client without a specific URL.
@@ -76,6 +76,9 @@ const (
// a GET request with a body.
DefaultSendGetBodyAs = "GET"
+ // DefaultGzipEnabled specifies if gzip compression is enabled by default.
+ DefaultGzipEnabled = false
+
// off is used to disable timeouts.
off = -1 * time.Second
)
@@ -132,6 +135,7 @@ type Client struct {
basicAuthPassword string // password for HTTP Basic Auth
sendGetBodyAs string // override for when sending a GET with a body
requiredPlugins []string // list of required plugins
+ gzipEnabled bool // gzip compression enabled or disabled (default)
retrier Retrier // strategy for retries
}
@@ -154,7 +158,7 @@ type Client struct {
//
// If the sniffer is enabled (the default), the new client then sniffes
// the cluster via the Nodes Info API
-// (see https://www.elastic.co/guide/en/elasticsearch/reference/6.0/cluster-nodes-info.html#cluster-nodes-info).
+// (see https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html#cluster-nodes-info).
// It uses the URLs specified by the caller. The caller is responsible
// to only pass a list of URLs of nodes that belong to the same cluster.
// This sniffing process is run on startup and periodically.
@@ -205,6 +209,7 @@ func NewClient(options ...ClientOptionFunc) (*Client, error) {
snifferCallback: nopSnifferCallback,
snifferStop: make(chan bool),
sendGetBodyAs: DefaultSendGetBodyAs,
+ gzipEnabled: DefaultGzipEnabled,
retrier: noRetries, // no retries by default
}
@@ -362,6 +367,7 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) {
snifferCallback: nopSnifferCallback,
snifferStop: make(chan bool),
sendGetBodyAs: DefaultSendGetBodyAs,
+ gzipEnabled: DefaultGzipEnabled,
retrier: noRetries, // no retries by default
}
@@ -590,6 +596,14 @@ func SetMaxRetries(maxRetries int) ClientOptionFunc {
}
}
+// SetGzip enables or disables gzip compression (disabled by default).
+func SetGzip(enabled bool) ClientOptionFunc {
+ return func(c *Client) error {
+ c.gzipEnabled = enabled
+ return nil
+ }
+}
+
// SetDecoder sets the Decoder to use when decoding data from Elasticsearch.
// DefaultDecoder is used by default.
func SetDecoder(decoder Decoder) ClientOptionFunc {
@@ -1075,11 +1089,6 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
var lastErr error
start := time.Now()
for {
- // Make a copy of the HTTP client provided via options to respect
- // settings like Basic Auth or a user-specified http.Transport.
- cl := new(http.Client)
- *cl = *c.c
- cl.Timeout = timeout
for _, url := range urls {
req, err := http.NewRequest("HEAD", url, nil)
if err != nil {
@@ -1088,7 +1097,10 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
if basicAuth {
req.SetBasicAuth(basicAuthUsername, basicAuthPassword)
}
- res, err := cl.Do(req)
+ ctx, cancel := context.WithTimeout(req.Context(), timeout)
+ defer cancel()
+ req = req.WithContext(ctx)
+ res, err := c.c.Do(req)
if err == nil && res != nil && res.StatusCode >= 200 && res.StatusCode < 300 {
return nil
} else if err != nil {
@@ -1096,7 +1108,7 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
}
}
time.Sleep(1 * time.Second)
- if time.Now().Sub(start) > timeout {
+ if time.Since(start) > timeout {
break
}
}
@@ -1173,12 +1185,38 @@ type PerformRequestOptions struct {
}
// PerformRequest does a HTTP request to Elasticsearch.
+// See PerformRequestWithContentType for details.
+func (c *Client) PerformRequest(ctx context.Context, method, path string, params url.Values, body interface{}, ignoreErrors ...int) (*Response, error) {
+ return c.PerformRequestWithOptions(ctx, PerformRequestOptions{
+ Method: method,
+ Path: path,
+ Params: params,
+ Body: body,
+ ContentType: "application/json",
+ IgnoreErrors: ignoreErrors,
+ })
+}
+
+// PerformRequestWithContentType executes a HTTP request with a specific content type.
// It returns a response (which might be nil) and an error on failure.
//
// Optionally, a list of HTTP error codes to ignore can be passed.
// This is necessary for services that expect e.g. HTTP status 404 as a
// valid outcome (Exists, IndicesExists, IndicesTypeExists).
-func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions) (*Response, error) {
+func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path string, params url.Values, body interface{}, contentType string, ignoreErrors ...int) (*Response, error) {
+ return c.PerformRequestWithOptions(ctx, PerformRequestOptions{
+ Method: method,
+ Path: path,
+ Params: params,
+ Body: body,
+ ContentType: contentType,
+ IgnoreErrors: ignoreErrors,
+ })
+}
+
+// PerformRequestWithOptions executes a HTTP request with the specified options.
+// It returns a response (which might be nil) and an error on failure.
+func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformRequestOptions) (*Response, error) {
start := time.Now().UTC()
c.mu.RLock()
@@ -1187,6 +1225,7 @@ func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions)
basicAuthUsername := c.basicAuthUsername
basicAuthPassword := c.basicAuthPassword
sendGetBodyAs := c.sendGetBodyAs
+ gzipEnabled := c.gzipEnabled
retrier := c.retrier
if opt.Retrier != nil {
retrier = opt.Retrier
@@ -1250,7 +1289,7 @@ func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions)
// Set body
if opt.Body != nil {
- err = req.SetBody(opt.Body)
+ err = req.SetBody(opt.Body, gzipEnabled)
if err != nil {
c.errorf("elastic: couldn't set body %+v for request: %v", opt.Body, err)
return nil, err
@@ -1297,11 +1336,6 @@ func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions)
// Tracing
c.dumpResponse(res)
- // Log deprecation warnings as errors
- if s := res.Header.Get("Warning"); s != "" {
- c.errorf(s)
- }
-
// Check for errors
if err := checkResponse((*http.Request)(req), res, opt.IgnoreErrors...); err != nil {
// No retry if request succeeded
@@ -1385,7 +1419,7 @@ func (c *Client) BulkProcessor() *BulkProcessorService {
// Reindex copies data from a source index into a destination index.
//
-// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-reindex.html
+// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-reindex.html
// for details on the Reindex API.
func (c *Client) Reindex() *ReindexService {
return NewReindexService(c)
@@ -1412,6 +1446,11 @@ func (c *Client) Search(indices ...string) *SearchService {
return NewSearchService(c).Index(indices...)
}
+// Suggest returns a service to return suggestions.
+func (c *Client) Suggest(indices ...string) *SuggestService {
+ return NewSuggestService(c).Index(indices...)
+}
+
// MultiSearch is the entry point for multi searches.
func (c *Client) MultiSearch() *MultiSearchService {
return NewMultiSearchService(c)
@@ -1428,15 +1467,28 @@ func (c *Client) Explain(index, typ, id string) *ExplainService {
}
// TODO Search Template
-// TODO Search Shards API
// TODO Search Exists API
-// TODO Validate API
+
+// Validate allows a user to validate a potentially expensive query without executing it.
+func (c *Client) Validate(indices ...string) *ValidateService {
+ return NewValidateService(c).Index(indices...)
+}
+
+// SearchShards returns statistical information about nodes and shards.
+func (c *Client) SearchShards(indices ...string) *SearchShardsService {
+ return NewSearchShardsService(c).Index(indices...)
+}
// FieldCaps returns statistical information about fields in indices.
func (c *Client) FieldCaps(indices ...string) *FieldCapsService {
return NewFieldCapsService(c).Index(indices...)
}
+// FieldStats returns statistical information about fields in indices.
+func (c *Client) FieldStats(indices ...string) *FieldStatsService {
+ return NewFieldStatsService(c).Index(indices...)
+}
+
// Exists checks if a document exists.
func (c *Client) Exists() *ExistsService {
return NewExistsService(c)
@@ -1556,6 +1608,24 @@ func (c *Client) Aliases() *AliasesService {
return NewAliasesService(c)
}
+// GetTemplate gets a search template.
+// Use IndexXXXTemplate funcs to manage index templates.
+func (c *Client) GetTemplate() *GetTemplateService {
+ return NewGetTemplateService(c)
+}
+
+// PutTemplate creates or updates a search template.
+// Use IndexXXXTemplate funcs to manage index templates.
+func (c *Client) PutTemplate() *PutTemplateService {
+ return NewPutTemplateService(c)
+}
+
+// DeleteTemplate deletes a search template.
+// Use IndexXXXTemplate funcs to manage index templates.
+func (c *Client) DeleteTemplate() *DeleteTemplateService {
+ return NewDeleteTemplateService(c)
+}
+
// IndexGetTemplate gets an index template.
// Use XXXTemplate funcs to manage search templates.
func (c *Client) IndexGetTemplate(names ...string) *IndicesGetTemplateService {