change dep to go module

This commit is contained in:
Jay
2018-11-16 11:10:19 +08:00
parent c21d43a691
commit ac1dcb7827
431 changed files with 43733 additions and 4366 deletions
-15
View File
@@ -4,24 +4,9 @@
"Sort": ["linter", "severity", "path", "line"],
"DisableAll": true,
"Enable": [
"deadcode",
"dupl",
"gocyclo",
"gofmt",
"goimports",
"golint",
"gosimple",
"ineffassign",
"interfacer",
"lll",
"megacheck",
"misspell",
"nakedret",
"structcheck",
"unconvert",
"unparam",
"unused",
"varcheck",
"vet"
],
"EnableGC": true,
+1 -1
View File
@@ -18,7 +18,7 @@ that we missed some features or changes. Feel free to change that.
To make it easy to review and understand your changes, please keep the
following things in mind before submitting your pull request:
* You compared the existing implemenation with the Java API, did you?
* You compared the existing implementation with the Java API, did you?
* Please work on the latest possible state of `olivere/elastic`.
Use `release-branch.v2` for targeting Elasticsearch 1.x and
`release-branch.v3` for targeting 2.x.
+3
View File
@@ -32,6 +32,7 @@ Bruce Zhou [@brucez-isell](https://github.com/brucez-isell)
Carl Dunham [@carldunham](https://github.com/carldunham)
César Jiménez [@cesarjimenez](https://github.com/cesarjimenez)
cforbes [@cforbes](https://github.com/cforbes)
張泰瑋(Chang Tai Wei) [@david30907d](https://github.com/david30907d)
Chris M [@tebriel](https://github.com/tebriel)
Chris Rice [@donutmonger](https://github.com/donutmonger)
Claudiu Olteanu [@claudiuolteanu](https://github.com/claudiuolteanu)
@@ -44,9 +45,11 @@ Corey Scott [@corsc](https://github.com/corsc)
Daniel Barrett [@shendaras](https://github.com/shendaras)
Daniel Heckrath [@DanielHeckrath](https://github.com/DanielHeckrath)
Daniel Imfeld [@dimfeld](https://github.com/dimfeld)
Daniel Santos [@danlsgiga](https://github.com/danlsgiga)
David Emanuel Buchmann [@wuurrd](https://github.com/wuurrd)
Dwayne Schultz [@myshkin5](https://github.com/myshkin5)
Ellison Leão [@ellisonleao](https://github.com/ellisonleao)
Erik Grinaker [@erikgrinaker](https://github.com/erikgrinaker)
Erwin [@eticzon](https://github.com/eticzon)
Eugene Egorov [@EugeneEgorov](https://github.com/EugeneEgorov)
Evan Shaw [@edsrzf](https://github.com/edsrzf)
+2 -1
View File
@@ -358,7 +358,8 @@ The cat APIs are not implemented as of now. We think they are better suited for
- Snapshot and Restore
- [x] Repositories
- [x] Snapshot
- [x] Snapshot create
- [x] Snapshot delete
- [ ] Restore
- [ ] Snapshot status
- [ ] Monitoring snapshot/restore status
+17 -1
View File
@@ -264,12 +264,28 @@ func (r *BulkUpdateRequest) Source() ([]string, error) {
lines[0] = string(body)
// 2nd line: {"doc" : { ... }} or {"script": {...}}
var doc interface{}
if r.doc != nil {
// Automatically serialize strings as raw JSON
switch t := r.doc.(type) {
default:
doc = r.doc
case string:
if len(t) > 0 {
doc = json.RawMessage(t)
}
case *string:
if t != nil && len(*t) > 0 {
doc = json.RawMessage(*t)
}
}
}
data := bulkUpdateRequestCommandData{
DocAsUpsert: r.docAsUpsert,
DetectNoop: r.detectNoop,
Upsert: r.upsert,
ScriptedUpsert: r.scriptedUpsert,
Doc: r.doc,
Doc: doc,
Source: r.returnSource,
}
if r.script != nil {
+39 -33
View File
@@ -26,7 +26,7 @@ import (
const (
// Version is the current version of Elastic.
Version = "6.2.8"
Version = "6.2.12"
// 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.
@@ -1230,14 +1230,15 @@ func (c *Client) mustActiveConn() error {
// PerformRequestOptions must be passed into PerformRequest.
type PerformRequestOptions struct {
Method string
Path string
Params url.Values
Body interface{}
ContentType string
IgnoreErrors []int
Retrier Retrier
Headers http.Header
Method string
Path string
Params url.Values
Body interface{}
ContentType string
IgnoreErrors []int
Retrier Retrier
Headers http.Header
MaxResponseSize int64
}
// PerformRequest does a HTTP request to Elasticsearch.
@@ -1376,14 +1377,14 @@ func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions)
if err := checkResponse((*http.Request)(req), res, opt.IgnoreErrors...); err != nil {
// No retry if request succeeded
// We still try to return a response.
resp, _ = c.newResponse(res)
resp, _ = c.newResponse(res, opt.MaxResponseSize)
return resp, err
}
// We successfully made a request with this connection
conn.MarkAsHealthy()
resp, err = c.newResponse(res)
resp, err = c.newResponse(res, opt.MaxResponseSize)
if err != nil {
return nil, err
}
@@ -1814,6 +1815,11 @@ func (c *Client) SnapshotCreateRepository(repository string) *SnapshotCreateRepo
return NewSnapshotCreateRepositoryService(c).Repository(repository)
}
// SnapshotDelete deletes a snapshot in a snapshot repository.
func (c *Client) SnapshotDelete(repository string, snapshot string) *SnapshotDeleteService {
return NewSnapshotDeleteService(c).Repository(repository).Snapshot(snapshot)
}
// SnapshotDeleteRepository deletes a snapshot repository.
func (c *Client) SnapshotDeleteRepository(repositories ...string) *SnapshotDeleteRepositoryService {
return NewSnapshotDeleteRepositoryService(c).Repository(repositories...)
@@ -1850,58 +1856,58 @@ func (c *Client) DeleteScript() *DeleteScriptService {
// -- X-Pack --
// XPackWatchPut adds a watch.
func (c *Client) XPackWatchPut() *XpackWatcherPutWatchService {
return NewXpackWatcherPutWatchService(c)
func (c *Client) XPackWatchPut(watchId string) *XPackWatcherPutWatchService {
return NewXPackWatcherPutWatchService(c).Id(watchId)
}
// XPackWatchGet gets a watch.
func (c *Client) XPackWatchGet() *XpackWatcherGetWatchService {
return NewXpackWatcherGetWatchService(c)
func (c *Client) XPackWatchGet(watchId string) *XPackWatcherGetWatchService {
return NewXPackWatcherGetWatchService(c).Id(watchId)
}
// XPackWatchDelete deletes a watch.
func (c *Client) XPackWatchDelete() *XpackWatcherDeleteWatchService {
return NewXpackWatcherDeleteWatchService(c)
func (c *Client) XPackWatchDelete(watchId string) *XPackWatcherDeleteWatchService {
return NewXPackWatcherDeleteWatchService(c).Id(watchId)
}
// XPackWatchExecute executes a watch.
func (c *Client) XPackWatchExecute() *XpackWatcherExecuteWatchService {
return NewXpackWatcherExecuteWatchService(c)
func (c *Client) XPackWatchExecute() *XPackWatcherExecuteWatchService {
return NewXPackWatcherExecuteWatchService(c)
}
// XPackWatchAck acknowledging a watch.
func (c *Client) XPackWatchAck() *XpackWatcherAckWatchService {
return NewXpackWatcherAckWatchService(c)
func (c *Client) XPackWatchAck(watchId string) *XPackWatcherAckWatchService {
return NewXPackWatcherAckWatchService(c).WatchId(watchId)
}
// XPackWatchActivate activates a watch.
func (c *Client) XPackWatchActivate() *XpackWatcherActivateWatchService {
return NewXpackWatcherActivateWatchService(c)
func (c *Client) XPackWatchActivate(watchId string) *XPackWatcherActivateWatchService {
return NewXPackWatcherActivateWatchService(c).WatchId(watchId)
}
// XPackWatchDeactivate deactivates a watch.
func (c *Client) XPackWatchDeactivate() *XpackWatcherDeactivateWatchService {
return NewXpackWatcherDeactivateWatchService(c)
func (c *Client) XPackWatchDeactivate(watchId string) *XPackWatcherDeactivateWatchService {
return NewXPackWatcherDeactivateWatchService(c).WatchId(watchId)
}
// XPackWatchStats returns the current Watcher metrics.
func (c *Client) XPackWatchStats() *XpackWatcherStatsService {
return NewXpackWatcherStatsService(c)
func (c *Client) XPackWatchStats() *XPackWatcherStatsService {
return NewXPackWatcherStatsService(c)
}
// XPackWatchStart starts a watch.
func (c *Client) XPackWatchStart() *XpackWatcherStartService {
return NewXpackWatcherStartService(c)
func (c *Client) XPackWatchStart() *XPackWatcherStartService {
return NewXPackWatcherStartService(c)
}
// XPackWatchStop stops a watch.
func (c *Client) XPackWatchStop() *XpackWatcherStopService {
return NewXpackWatcherStopService(c)
func (c *Client) XPackWatchStop() *XPackWatcherStopService {
return NewXPackWatcherStopService(c)
}
// XPackWatchRestart restarts a watch.
func (c *Client) XPackWatchRestart() *XpackWatcherRestartService {
return NewXpackWatcherRestartService(c)
func (c *Client) XPackWatchRestart() *XPackWatcherRestartService {
return NewXPackWatcherRestartService(c)
}
// -- Helpers and shortcuts --
+5 -3
View File
@@ -2,7 +2,7 @@ version: '3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.1
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.2
hostname: elasticsearch
environment:
- cluster.name=elasticsearch
@@ -25,12 +25,14 @@ services:
ports:
- 9200:9200
platinum:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.1
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
hostname: elasticsearch-platinum
environment:
- cluster.name=platinum
- bootstrap.memory_lock=true
# - xpack.security.enabled=false
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.watcher.enabled=true
# - http.host=0.0.0.0
# - transport.host=127.0.0.1
# - network.host=_local_
+19 -2
View File
@@ -6,10 +6,17 @@ package elastic
import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
)
var (
// ErrResponseSize is raised if a response body exceeds the given max body size.
ErrResponseSize = errors.New("elastic: response size too large")
)
// Response represents a response from Elasticsearch.
type Response struct {
// StatusCode is the HTTP status code, e.g. 200.
@@ -22,16 +29,26 @@ type Response struct {
}
// newResponse creates a new response from the HTTP response.
func (c *Client) newResponse(res *http.Response) (*Response, error) {
func (c *Client) newResponse(res *http.Response, maxBodySize int64) (*Response, error) {
r := &Response{
StatusCode: res.StatusCode,
Header: res.Header,
}
if res.Body != nil {
slurp, err := ioutil.ReadAll(res.Body)
body := io.Reader(res.Body)
if maxBodySize > 0 {
if res.ContentLength > maxBodySize {
return nil, ErrResponseSize
}
body = io.LimitReader(body, maxBodySize+1)
}
slurp, err := ioutil.ReadAll(body)
if err != nil {
return nil, err
}
if maxBodySize > 0 && int64(len(slurp)) > maxBodySize {
return nil, ErrResponseSize
}
// HEAD requests return a body but no content
if len(slurp) > 0 {
r.Body = json.RawMessage(slurp)
Generated Vendored Executable → Regular
View File
+22 -12
View File
@@ -38,6 +38,7 @@ type ScrollService struct {
allowNoIndices *bool
expandWildcards string
headers http.Header
maxResponseSize int64
mu sync.RWMutex
scrollId string
@@ -238,6 +239,13 @@ func (s *ScrollService) ExpandWildcards(expandWildcards string) *ScrollService {
return s
}
// MaxResponseSize sets an upper limit on the response body size that we accept,
// to guard against OOM situations.
func (s *ScrollService) MaxResponseSize(maxResponseSize int64) *ScrollService {
s.maxResponseSize = maxResponseSize
return s
}
// ScrollId specifies the identifier of a scroll in action.
func (s *ScrollService) ScrollId(scrollId string) *ScrollService {
s.mu.Lock()
@@ -309,12 +317,13 @@ func (s *ScrollService) first(ctx context.Context) (*SearchResult, error) {
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
Retrier: s.retrier,
Headers: s.headers,
Method: "POST",
Path: path,
Params: params,
Body: body,
Retrier: s.retrier,
Headers: s.headers,
MaxResponseSize: s.maxResponseSize,
})
if err != nil {
return nil, err
@@ -430,12 +439,13 @@ func (s *ScrollService) next(ctx context.Context) (*SearchResult, error) {
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
Retrier: s.retrier,
Headers: s.headers,
Method: "POST",
Path: path,
Params: params,
Body: body,
Retrier: s.retrier,
Headers: s.headers,
MaxResponseSize: s.maxResponseSize,
})
if err != nil {
return nil, err
+42 -33
View File
@@ -31,6 +31,7 @@ type SearchService struct {
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
maxResponseSize int64
}
// NewSearchService creates a new service for searching in Elasticsearch.
@@ -312,6 +313,13 @@ func (s *SearchService) ExpandWildcards(expandWildcards string) *SearchService {
return s
}
// MaxResponseSize sets an upper limit on the response body size that we accept,
// to guard against OOM situations.
func (s *SearchService) MaxResponseSize(maxResponseSize int64) *SearchService {
s.maxResponseSize = maxResponseSize
return s
}
// buildURL builds the URL for the operation.
func (s *SearchService) buildURL() (string, url.Values, error) {
var err error
@@ -399,10 +407,11 @@ func (s *SearchService) Do(ctx context.Context) (*SearchResult, error) {
body = src
}
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
Method: "POST",
Path: path,
Params: params,
Body: body,
MaxResponseSize: s.maxResponseSize,
})
if err != nil {
return nil, err
@@ -418,15 +427,15 @@ func (s *SearchService) Do(ctx context.Context) (*SearchResult, error) {
// SearchResult is the result of a search in Elasticsearch.
type SearchResult struct {
TookInMillis int64 `json:"took"` // search time in milliseconds
ScrollId string `json:"_scroll_id"` // only used with Scroll and Scan operations
Hits *SearchHits `json:"hits"` // the actual search hits
Suggest SearchSuggest `json:"suggest"` // results from suggesters
Aggregations Aggregations `json:"aggregations"` // results from aggregations
TimedOut bool `json:"timed_out"` // true if the search timed out
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet
Profile *SearchProfile `json:"profile,omitempty"` // profiling results, if optional Profile API was active for this search
Shards *shardsInfo `json:"_shards,omitempty"` // shard information
TookInMillis int64 `json:"took,omitempty"` // search time in milliseconds
ScrollId string `json:"_scroll_id,omitempty"` // only used with Scroll and Scan operations
Hits *SearchHits `json:"hits,omitempty"` // the actual search hits
Suggest SearchSuggest `json:"suggest,omitempty"` // results from suggesters
Aggregations Aggregations `json:"aggregations,omitempty"` // results from aggregations
TimedOut bool `json:"timed_out,omitempty"` // true if the search timed out
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet
Profile *SearchProfile `json:"profile,omitempty"` // profiling results, if optional Profile API was active for this search
Shards *shardsInfo `json:"_shards,omitempty"` // shard information
}
// TotalHits is a convenience function to return the number of hits for
@@ -462,9 +471,9 @@ func (r *SearchResult) Each(typ reflect.Type) []interface{} {
// SearchHits specifies the list of search hits.
type SearchHits struct {
TotalHits int64 `json:"total"` // total number of hits found
MaxScore *float64 `json:"max_score"` // maximum score of all hits
Hits []*SearchHit `json:"hits"` // the actual hits returned
TotalHits int64 `json:"total"` // total number of hits found
MaxScore *float64 `json:"max_score,omitempty"` // maximum score of all hits
Hits []*SearchHit `json:"hits,omitempty"` // the actual hits returned
}
// NestedHit is a nested innerhit
@@ -476,22 +485,22 @@ type NestedHit struct {
// SearchHit is a single hit.
type SearchHit struct {
Score *float64 `json:"_score"` // computed score
Index string `json:"_index"` // index name
Type string `json:"_type"` // type meta field
Id string `json:"_id"` // external or internal
Uid string `json:"_uid"` // uid meta field (see MapperService.java for all meta fields)
Routing string `json:"_routing"` // routing meta field
Parent string `json:"_parent"` // parent meta field
Version *int64 `json:"_version"` // version number, when Version is set to true in SearchService
Sort []interface{} `json:"sort"` // sort information
Highlight SearchHitHighlight `json:"highlight"` // highlighter information
Source *json.RawMessage `json:"_source"` // stored document source
Fields map[string]interface{} `json:"fields"` // returned (stored) fields
Explanation *SearchExplanation `json:"_explanation"` // explains how the score was computed
MatchedQueries []string `json:"matched_queries"` // matched queries
InnerHits map[string]*SearchHitInnerHits `json:"inner_hits"` // inner hits with ES >= 1.5.0
Nested *NestedHit `json:"_nested"` // for nested inner hits
Score *float64 `json:"_score,omitempty"` // computed score
Index string `json:"_index,omitempty"` // index name
Type string `json:"_type,omitempty"` // type meta field
Id string `json:"_id,omitempty"` // external or internal
Uid string `json:"_uid,omitempty"` // uid meta field (see MapperService.java for all meta fields)
Routing string `json:"_routing,omitempty"` // routing meta field
Parent string `json:"_parent,omitempty"` // parent meta field
Version *int64 `json:"_version,omitempty"` // version number, when Version is set to true in SearchService
Sort []interface{} `json:"sort,omitempty"` // sort information
Highlight SearchHitHighlight `json:"highlight,omitempty"` // highlighter information
Source *json.RawMessage `json:"_source,omitempty"` // stored document source
Fields map[string]interface{} `json:"fields,omitempty"` // returned (stored) fields
Explanation *SearchExplanation `json:"_explanation,omitempty"` // explains how the score was computed
MatchedQueries []string `json:"matched_queries,omitempty"` // matched queries
InnerHits map[string]*SearchHitInnerHits `json:"inner_hits,omitempty"` // inner hits with ES >= 1.5.0
Nested *NestedHit `json:"_nested,omitempty"` // for nested inner hits
// Shard
// HighlightFields
@@ -501,7 +510,7 @@ type SearchHit struct {
// SearchHitInnerHits is used for inner hits.
type SearchHitInnerHits struct {
Hits *SearchHits `json:"hits"`
Hits *SearchHits `json:"hits,omitempty"`
}
// SearchExplanation explains how the score for a hit was computed.
+1 -1
View File
@@ -176,7 +176,7 @@ func (q *MatchQuery) Source() (interface{}, error) {
query["zero_terms_query"] = q.zeroTermsQuery
}
if q.cutoffFrequency != nil {
query["cutoff_frequency"] = q.cutoffFrequency
query["cutoff_frequency"] = *q.cutoffFrequency
}
if q.boost != nil {
query["boost"] = *q.boost
+106
View File
@@ -0,0 +1,106 @@
// Copyright 2012-present Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
import (
"context"
"encoding/json"
"fmt"
"net/url"
"github.com/olivere/elastic/uritemplates"
)
// SnapshotDeleteService deletes a snapshot from a snapshot repository.
// It is documented at
// https://www.elastic.co/guide/en/elasticsearch/reference/6.4/modules-snapshots.html.
type SnapshotDeleteService struct {
client *Client
repository string
snapshot string
}
// NewSnapshotDeleteService creates a new SnapshotDeleteService.
func NewSnapshotDeleteService(client *Client) *SnapshotDeleteService {
return &SnapshotDeleteService{
client: client,
}
}
// Repository is the repository name.
func (s *SnapshotDeleteService) Repository(repository string) *SnapshotDeleteService {
s.repository = repository
return s
}
// Snapshot is the snapshot name.
func (s *SnapshotDeleteService) Snapshot(snapshot string) *SnapshotDeleteService {
s.snapshot = snapshot
return s
}
// buildURL builds the URL for the operation.
func (s *SnapshotDeleteService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_snapshot/{repository}/{snapshot}", map[string]string{
"repository": s.repository,
"snapshot": s.snapshot,
})
if err != nil {
return "", url.Values{}, err
}
return path, url.Values{}, nil
}
// Validate checks if the operation is valid.
func (s *SnapshotDeleteService) Validate() error {
var invalid []string
if s.repository == "" {
invalid = append(invalid, "Repository")
}
if s.snapshot == "" {
invalid = append(invalid, "Snapshot")
}
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
}
return nil
}
// Do executes the operation.
func (s *SnapshotDeleteService) Do(ctx context.Context) (*SnapshotDeleteResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
}
// Get URL for request
path, params, err := s.buildURL()
if err != nil {
return nil, err
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "DELETE",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(SnapshotDeleteResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// SnapshotDeleteResponse is the response of SnapshotDeleteService.Do.
type SnapshotDeleteResponse struct {
Acknowledged bool `json:"acknowledged"`
}
+61 -21
View File
@@ -25,9 +25,12 @@ type SortInfo struct {
IgnoreUnmapped *bool
UnmappedType string
SortMode string
NestedFilter Query
NestedPath string
NestedSort *NestedSort // available in 6.1 or later
NestedFilter Query // deprecated in 6.1 and replaced by Filter
Filter Query
NestedPath string // deprecated in 6.1 and replaced by Path
Path string
NestedSort *NestedSort // deprecated in 6.1 and replaced by Nested
Nested *NestedSort
}
func (info SortInfo) Source() (interface{}, error) {
@@ -49,17 +52,31 @@ func (info SortInfo) Source() (interface{}, error) {
if info.SortMode != "" {
prop["mode"] = info.SortMode
}
if info.NestedFilter != nil {
if info.Filter != nil {
src, err := info.Filter.Source()
if err != nil {
return nil, err
}
prop["filter"] = src
} else if info.NestedFilter != nil {
src, err := info.NestedFilter.Source()
if err != nil {
return nil, err
}
prop["nested_filter"] = src
prop["nested_filter"] = src // deprecated in 6.1
}
if info.NestedPath != "" {
prop["nested_path"] = info.NestedPath
if info.Path != "" {
prop["path"] = info.Path
} else if info.NestedPath != "" {
prop["nested_path"] = info.NestedPath // deprecated in 6.1
}
if info.NestedSort != nil {
if info.Nested != nil {
src, err := info.Nested.Source()
if err != nil {
return nil, err
}
prop["nested"] = src
} else if info.NestedSort != nil {
src, err := info.NestedSort.Source()
if err != nil {
return nil, err
@@ -142,9 +159,9 @@ type FieldSort struct {
missing interface{}
unmappedType *string
sortMode *string
nestedFilter Query
nestedPath *string
nestedSort *NestedSort
filter Query
path *string
nested *NestedSort
}
// NewFieldSort creates a new FieldSort.
@@ -204,22 +221,45 @@ func (s *FieldSort) SortMode(sortMode string) *FieldSort {
// NestedFilter sets a filter that nested objects should match with
// in order to be taken into account for sorting.
// Deprecated: Use Filter instead.
func (s *FieldSort) NestedFilter(nestedFilter Query) *FieldSort {
s.nestedFilter = nestedFilter
s.filter = nestedFilter
return s
}
// Filter sets a filter that nested objects should match with
// in order to be taken into account for sorting.
func (s *FieldSort) Filter(filter Query) *FieldSort {
s.filter = filter
return s
}
// NestedPath is used if sorting occurs on a field that is inside a
// nested object.
// Deprecated: Use Path instead.
func (s *FieldSort) NestedPath(nestedPath string) *FieldSort {
s.nestedPath = &nestedPath
s.path = &nestedPath
return s
}
// Path is used if sorting occurs on a field that is inside a
// nested object.
func (s *FieldSort) Path(path string) *FieldSort {
s.path = &path
return s
}
// NestedSort is available starting with 6.1 and will replace NestedFilter
// and NestedPath.
// Deprecated: Use Nested instead.
func (s *FieldSort) NestedSort(nestedSort *NestedSort) *FieldSort {
s.nestedSort = nestedSort
s.nested = nestedSort
return s
}
// Nested is available starting with 6.1 and will replace Filter and Path.
func (s *FieldSort) Nested(nested *NestedSort) *FieldSort {
s.nested = nested
return s
}
@@ -242,18 +282,18 @@ func (s *FieldSort) Source() (interface{}, error) {
if s.sortMode != nil {
x["mode"] = *s.sortMode
}
if s.nestedFilter != nil {
src, err := s.nestedFilter.Source()
if s.filter != nil {
src, err := s.filter.Source()
if err != nil {
return nil, err
}
x["nested_filter"] = src
x["filter"] = src
}
if s.nestedPath != nil {
x["nested_path"] = *s.nestedPath
if s.path != nil {
x["path"] = *s.path
}
if s.nestedSort != nil {
src, err := s.nestedSort.Source()
if s.nested != nil {
src, err := s.nested.Source()
if err != nil {
return nil, err
}
+40 -51
View File
@@ -14,68 +14,65 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherAckWatchService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html.
type XpackWatcherAckWatchService struct {
// XPackWatcherAckWatchService enables you to manually throttle execution of the watchs actions.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-ack-watch.html.
type XPackWatcherAckWatchService struct {
client *Client
pretty bool
watchId string
actionId []string
masterTimeout string
bodyJson interface{}
bodyString string
}
// NewXpackWatcherAckWatchService creates a new XpackWatcherAckWatchService.
func NewXpackWatcherAckWatchService(client *Client) *XpackWatcherAckWatchService {
return &XpackWatcherAckWatchService{
client: client,
actionId: make([]string, 0),
// NewXPackWatcherAckWatchService creates a new XPackWatcherAckWatchService.
func NewXPackWatcherAckWatchService(client *Client) *XPackWatcherAckWatchService {
return &XPackWatcherAckWatchService{
client: client,
}
}
// WatchId is documented as: Watch ID.
func (s *XpackWatcherAckWatchService) WatchId(watchId string) *XpackWatcherAckWatchService {
// WatchId is the unique ID of the watch.
func (s *XPackWatcherAckWatchService) WatchId(watchId string) *XPackWatcherAckWatchService {
s.watchId = watchId
return s
}
// ActionId is documented as: A comma-separated list of the action ids to be acked.
func (s *XpackWatcherAckWatchService) ActionId(actionId []string) *XpackWatcherAckWatchService {
s.actionId = actionId
// ActionId is a slice of action ids to be acked.
func (s *XPackWatcherAckWatchService) ActionId(actionId ...string) *XPackWatcherAckWatchService {
s.actionId = append(s.actionId, actionId...)
return s
}
// MasterTimeout is documented as: Explicit operation timeout for connection to master node.
func (s *XpackWatcherAckWatchService) MasterTimeout(masterTimeout string) *XpackWatcherAckWatchService {
// MasterTimeout indicates an explicit operation timeout for
// connection to master node.
func (s *XPackWatcherAckWatchService) MasterTimeout(masterTimeout string) *XPackWatcherAckWatchService {
s.masterTimeout = masterTimeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherAckWatchService) Pretty(pretty bool) *XpackWatcherAckWatchService {
func (s *XPackWatcherAckWatchService) Pretty(pretty bool) *XPackWatcherAckWatchService {
s.pretty = pretty
return s
}
// BodyJson is documented as: Execution control.
func (s *XpackWatcherAckWatchService) BodyJson(body interface{}) *XpackWatcherAckWatchService {
s.bodyJson = body
return s
}
// BodyString is documented as: Execution control.
func (s *XpackWatcherAckWatchService) BodyString(body string) *XpackWatcherAckWatchService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherAckWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherAckWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_ack", map[string]string{
"action_id": strings.Join(s.actionId, ","),
"watch_id": s.watchId,
})
var (
path string
err error
)
if len(s.actionId) > 0 {
path, err = uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_ack/{action_id}", map[string]string{
"watch_id": s.watchId,
"action_id": strings.Join(s.actionId, ","),
})
} else {
path, err = uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_ack", map[string]string{
"watch_id": s.watchId,
})
}
if err != nil {
return "", url.Values{}, err
}
@@ -83,7 +80,7 @@ func (s *XpackWatcherAckWatchService) buildURL() (string, url.Values, error) {
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
@@ -92,7 +89,7 @@ func (s *XpackWatcherAckWatchService) buildURL() (string, url.Values, error) {
}
// Validate checks if the operation is valid.
func (s *XpackWatcherAckWatchService) Validate() error {
func (s *XPackWatcherAckWatchService) Validate() error {
var invalid []string
if s.watchId == "" {
invalid = append(invalid, "WatchId")
@@ -104,7 +101,7 @@ func (s *XpackWatcherAckWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherAckWatchService) Do(ctx context.Context) (*XpackWatcherAckWatchResponse, error) {
func (s *XPackWatcherAckWatchService) Do(ctx context.Context) (*XPackWatcherAckWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -116,39 +113,31 @@ func (s *XpackWatcherAckWatchService) Do(ctx context.Context) (*XpackWatcherAckW
return nil, err
}
// Setup HTTP request body
var body interface{}
if s.bodyJson != nil {
body = s.bodyJson
} else {
body = s.bodyString
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(XpackWatcherAckWatchResponse)
ret := new(XPackWatcherAckWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherAckWatchResponse is the response of XpackWatcherAckWatchService.Do.
type XpackWatcherAckWatchResponse struct {
Status AckWatchStatus `json:"status"`
// XPackWatcherAckWatchResponse is the response of XPackWatcherAckWatchService.Do.
type XPackWatcherAckWatchResponse struct {
Status *XPackWatcherAckWatchStatus `json:"status"`
}
type AckWatchStatus struct {
// XPackWatcherAckWatchStatus is the status of a XPackWatcherAckWatchResponse.
type XPackWatcherAckWatchStatus struct {
State map[string]interface{} `json:"state"`
LastChecked string `json:"last_checked"`
LastMetCondition string `json:"last_met_condition"`
+19 -41
View File
@@ -13,55 +13,42 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherActivateWatchService is documented at https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html.
type XpackWatcherActivateWatchService struct {
// XPackWatcherActivateWatchService enables you to activate a currently inactive watch.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-activate-watch.html.
type XPackWatcherActivateWatchService struct {
client *Client
pretty bool
watchId string
masterTimeout string
bodyJson interface{}
bodyString string
}
// NewXpackWatcherActivateWatchService creates a new XpackWatcherActivateWatchService.
func NewXpackWatcherActivateWatchService(client *Client) *XpackWatcherActivateWatchService {
return &XpackWatcherActivateWatchService{
// NewXPackWatcherActivateWatchService creates a new XPackWatcherActivateWatchService.
func NewXPackWatcherActivateWatchService(client *Client) *XPackWatcherActivateWatchService {
return &XPackWatcherActivateWatchService{
client: client,
}
}
// WatchId is documented as: Watch ID.
func (s *XpackWatcherActivateWatchService) WatchId(watchId string) *XpackWatcherActivateWatchService {
// WatchId is the ID of the watch to activate.
func (s *XPackWatcherActivateWatchService) WatchId(watchId string) *XPackWatcherActivateWatchService {
s.watchId = watchId
return s
}
// MasterTimeout is documented as: Explicit operation timeout for connection to master node.
func (s *XpackWatcherActivateWatchService) MasterTimeout(masterTimeout string) *XpackWatcherActivateWatchService {
// MasterTimeout specifies an explicit operation timeout for connection to master node.
func (s *XPackWatcherActivateWatchService) MasterTimeout(masterTimeout string) *XPackWatcherActivateWatchService {
s.masterTimeout = masterTimeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherActivateWatchService) Pretty(pretty bool) *XpackWatcherActivateWatchService {
func (s *XPackWatcherActivateWatchService) Pretty(pretty bool) *XPackWatcherActivateWatchService {
s.pretty = pretty
return s
}
// BodyJson is documented as: Execution control.
func (s *XpackWatcherActivateWatchService) BodyJson(body interface{}) *XpackWatcherActivateWatchService {
s.bodyJson = body
return s
}
// BodyString is documented as: Execution control.
func (s *XpackWatcherActivateWatchService) BodyString(body string) *XpackWatcherActivateWatchService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherActivateWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherActivateWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_activate", map[string]string{
"watch_id": s.watchId,
@@ -73,7 +60,7 @@ func (s *XpackWatcherActivateWatchService) buildURL() (string, url.Values, error
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
@@ -82,7 +69,7 @@ func (s *XpackWatcherActivateWatchService) buildURL() (string, url.Values, error
}
// Validate checks if the operation is valid.
func (s *XpackWatcherActivateWatchService) Validate() error {
func (s *XPackWatcherActivateWatchService) Validate() error {
var invalid []string
if s.watchId == "" {
invalid = append(invalid, "WatchId")
@@ -94,7 +81,7 @@ func (s *XpackWatcherActivateWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherActivateWatchService) Do(ctx context.Context) (*XpackWatcherActivateWatchResponse, error) {
func (s *XPackWatcherActivateWatchService) Do(ctx context.Context) (*XPackWatcherActivateWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -106,34 +93,25 @@ func (s *XpackWatcherActivateWatchService) Do(ctx context.Context) (*XpackWatche
return nil, err
}
// Setup HTTP request body
var body interface{}
if s.bodyJson != nil {
body = s.bodyJson
} else {
body = s.bodyString
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(XpackWatcherActivateWatchResponse)
ret := new(XPackWatcherActivateWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherActivateWatchResponse is the response of XpackWatcherActivateWatchService.Do.
type XpackWatcherActivateWatchResponse struct {
Status WatchStatus `json:"status"`
// XPackWatcherActivateWatchResponse is the response of XPackWatcherActivateWatchService.Do.
type XPackWatcherActivateWatchResponse struct {
Status *XPackWatchStatus `json:"status"`
}
+19 -39
View File
@@ -13,8 +13,9 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherDeactivateWatchService is documented at https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-deactivate-watch.html.
type XpackWatcherDeactivateWatchService struct {
// XPackWatcherDeactivateWatchService enables you to deactivate a currently active watch.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-deactivate-watch.html.
type XPackWatcherDeactivateWatchService struct {
client *Client
pretty bool
watchId string
@@ -23,45 +24,33 @@ type XpackWatcherDeactivateWatchService struct {
bodyString string
}
// NewXpackWatcherDeactivateWatchService creates a new XpackWatcherDeactivateWatchService.
func NewXpackWatcherDeactivateWatchService(client *Client) *XpackWatcherDeactivateWatchService {
return &XpackWatcherDeactivateWatchService{
// NewXPackWatcherDeactivateWatchService creates a new XPackWatcherDeactivateWatchService.
func NewXPackWatcherDeactivateWatchService(client *Client) *XPackWatcherDeactivateWatchService {
return &XPackWatcherDeactivateWatchService{
client: client,
}
}
// WatchId is documented as: Watch ID.
func (s *XpackWatcherDeactivateWatchService) WatchId(watchId string) *XpackWatcherDeactivateWatchService {
// WatchId is the ID of the watch to deactivate.
func (s *XPackWatcherDeactivateWatchService) WatchId(watchId string) *XPackWatcherDeactivateWatchService {
s.watchId = watchId
return s
}
// MasterTimeout is documented as: Explicit operation timeout for connection to master node.
func (s *XpackWatcherDeactivateWatchService) MasterTimeout(masterTimeout string) *XpackWatcherDeactivateWatchService {
// MasterTimeout specifies an explicit operation timeout for connection to master node.
func (s *XPackWatcherDeactivateWatchService) MasterTimeout(masterTimeout string) *XPackWatcherDeactivateWatchService {
s.masterTimeout = masterTimeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherDeactivateWatchService) Pretty(pretty bool) *XpackWatcherDeactivateWatchService {
func (s *XPackWatcherDeactivateWatchService) Pretty(pretty bool) *XPackWatcherDeactivateWatchService {
s.pretty = pretty
return s
}
// BodyJson is documented as: Execution control.
func (s *XpackWatcherDeactivateWatchService) BodyJson(body interface{}) *XpackWatcherDeactivateWatchService {
s.bodyJson = body
return s
}
// BodyString is documented as: Execution control.
func (s *XpackWatcherDeactivateWatchService) BodyString(body string) *XpackWatcherDeactivateWatchService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherDeactivateWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherDeactivateWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_deactivate", map[string]string{
"watch_id": s.watchId,
@@ -73,7 +62,7 @@ func (s *XpackWatcherDeactivateWatchService) buildURL() (string, url.Values, err
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
@@ -82,7 +71,7 @@ func (s *XpackWatcherDeactivateWatchService) buildURL() (string, url.Values, err
}
// Validate checks if the operation is valid.
func (s *XpackWatcherDeactivateWatchService) Validate() error {
func (s *XPackWatcherDeactivateWatchService) Validate() error {
var invalid []string
if s.watchId == "" {
invalid = append(invalid, "WatchId")
@@ -94,7 +83,7 @@ func (s *XpackWatcherDeactivateWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherDeactivateWatchService) Do(ctx context.Context) (*XpackWatcherDeactivateWatchResponse, error) {
func (s *XPackWatcherDeactivateWatchService) Do(ctx context.Context) (*XPackWatcherDeactivateWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -106,34 +95,25 @@ func (s *XpackWatcherDeactivateWatchService) Do(ctx context.Context) (*XpackWatc
return nil, err
}
// Setup HTTP request body
var body interface{}
if s.bodyJson != nil {
body = s.bodyJson
} else {
body = s.bodyString
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(XpackWatcherDeactivateWatchResponse)
ret := new(XPackWatcherDeactivateWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherDeactivateWatchResponse is the response of XpackWatcherDeactivateWatchService.Do.
type XpackWatcherDeactivateWatchResponse struct {
Status WatchStatus `json:"status"`
// XPackWatcherDeactivateWatchResponse is the response of XPackWatcherDeactivateWatchService.Do.
type XPackWatcherDeactivateWatchResponse struct {
Status *XPackWatchStatus `json:"status"`
}
+18 -17
View File
@@ -13,41 +13,42 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherDeleteWatchService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-delete-watch.html.
type XpackWatcherDeleteWatchService struct {
// XPackWatcherDeleteWatchService removes a watch.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-delete-watch.html.
type XPackWatcherDeleteWatchService struct {
client *Client
pretty bool
id string
masterTimeout string
}
// NewXpackWatcherDeleteWatchService creates a new XpackWatcherDeleteWatchService.
func NewXpackWatcherDeleteWatchService(client *Client) *XpackWatcherDeleteWatchService {
return &XpackWatcherDeleteWatchService{
// NewXPackWatcherDeleteWatchService creates a new XPackWatcherDeleteWatchService.
func NewXPackWatcherDeleteWatchService(client *Client) *XPackWatcherDeleteWatchService {
return &XPackWatcherDeleteWatchService{
client: client,
}
}
// Id is documented as: Watch ID.
func (s *XpackWatcherDeleteWatchService) Id(id string) *XpackWatcherDeleteWatchService {
// Id of the watch to delete.
func (s *XPackWatcherDeleteWatchService) Id(id string) *XPackWatcherDeleteWatchService {
s.id = id
return s
}
// MasterTimeout is documented as: Explicit operation timeout for connection to master node.
func (s *XpackWatcherDeleteWatchService) MasterTimeout(masterTimeout string) *XpackWatcherDeleteWatchService {
// MasterTimeout specifies an explicit operation timeout for connection to master node.
func (s *XPackWatcherDeleteWatchService) MasterTimeout(masterTimeout string) *XPackWatcherDeleteWatchService {
s.masterTimeout = masterTimeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherDeleteWatchService) Pretty(pretty bool) *XpackWatcherDeleteWatchService {
func (s *XPackWatcherDeleteWatchService) Pretty(pretty bool) *XPackWatcherDeleteWatchService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherDeleteWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherDeleteWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{id}", map[string]string{
"id": s.id,
@@ -59,7 +60,7 @@ func (s *XpackWatcherDeleteWatchService) buildURL() (string, url.Values, error)
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
@@ -68,7 +69,7 @@ func (s *XpackWatcherDeleteWatchService) buildURL() (string, url.Values, error)
}
// Validate checks if the operation is valid.
func (s *XpackWatcherDeleteWatchService) Validate() error {
func (s *XPackWatcherDeleteWatchService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
@@ -80,7 +81,7 @@ func (s *XpackWatcherDeleteWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherDeleteWatchService) Do(ctx context.Context) (*XpackWatcherDeleteWatchResponse, error) {
func (s *XPackWatcherDeleteWatchService) Do(ctx context.Context) (*XPackWatcherDeleteWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -103,15 +104,15 @@ func (s *XpackWatcherDeleteWatchService) Do(ctx context.Context) (*XpackWatcherD
}
// Return operation response
ret := new(XpackWatcherDeleteWatchResponse)
ret := new(XPackWatcherDeleteWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherDeleteWatchResponse is the response of XpackWatcherDeleteWatchService.Do.
type XpackWatcherDeleteWatchResponse struct {
// XPackWatcherDeleteWatchResponse is the response of XPackWatcherDeleteWatchService.Do.
type XPackWatcherDeleteWatchResponse struct {
Found bool `json:"found"`
Id string `json:"_id"`
Version int `json:"_version"`
+37 -28
View File
@@ -13,8 +13,9 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherExecuteWatchService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html.
type XpackWatcherExecuteWatchService struct {
// XPackWatcherExecuteWatchService forces the execution of a stored watch.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-execute-watch.html.
type XPackWatcherExecuteWatchService struct {
client *Client
pretty bool
id string
@@ -23,49 +24,57 @@ type XpackWatcherExecuteWatchService struct {
bodyString string
}
// NewXpackWatcherExecuteWatchService creates a new XpackWatcherExecuteWatchService.
func NewXpackWatcherExecuteWatchService(client *Client) *XpackWatcherExecuteWatchService {
return &XpackWatcherExecuteWatchService{
// NewXPackWatcherExecuteWatchService creates a new XPackWatcherExecuteWatchService.
func NewXPackWatcherExecuteWatchService(client *Client) *XPackWatcherExecuteWatchService {
return &XPackWatcherExecuteWatchService{
client: client,
}
}
// Id is documented as: Watch ID.
func (s *XpackWatcherExecuteWatchService) Id(id string) *XpackWatcherExecuteWatchService {
// Id of the watch to execute on.
func (s *XPackWatcherExecuteWatchService) Id(id string) *XPackWatcherExecuteWatchService {
s.id = id
return s
}
// Debug is documented as: indicates whether the watch should execute in debug mode.
func (s *XpackWatcherExecuteWatchService) Debug(debug bool) *XpackWatcherExecuteWatchService {
// Debug indicates whether the watch should execute in debug mode.
func (s *XPackWatcherExecuteWatchService) Debug(debug bool) *XPackWatcherExecuteWatchService {
s.debug = &debug
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherExecuteWatchService) Pretty(pretty bool) *XpackWatcherExecuteWatchService {
func (s *XPackWatcherExecuteWatchService) Pretty(pretty bool) *XPackWatcherExecuteWatchService {
s.pretty = pretty
return s
}
// BodyJson is documented as: Execution control.
func (s *XpackWatcherExecuteWatchService) BodyJson(body interface{}) *XpackWatcherExecuteWatchService {
func (s *XPackWatcherExecuteWatchService) BodyJson(body interface{}) *XPackWatcherExecuteWatchService {
s.bodyJson = body
return s
}
// BodyString is documented as: Execution control.
func (s *XpackWatcherExecuteWatchService) BodyString(body string) *XpackWatcherExecuteWatchService {
func (s *XPackWatcherExecuteWatchService) BodyString(body string) *XPackWatcherExecuteWatchService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherExecuteWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherExecuteWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{id}/_execute", map[string]string{
"id": s.id,
})
var (
path string
err error
)
if s.id != "" {
path, err = uritemplates.Expand("/_xpack/watcher/watch/{id}/_execute", map[string]string{
"id": s.id,
})
} else {
path = "/_xpack/watcher/watch/_execute"
}
if err != nil {
return "", url.Values{}, err
}
@@ -73,7 +82,7 @@ func (s *XpackWatcherExecuteWatchService) buildURL() (string, url.Values, error)
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.debug != nil {
params.Set("debug", fmt.Sprintf("%v", *s.debug))
@@ -82,12 +91,12 @@ func (s *XpackWatcherExecuteWatchService) buildURL() (string, url.Values, error)
}
// Validate checks if the operation is valid.
func (s *XpackWatcherExecuteWatchService) Validate() error {
func (s *XPackWatcherExecuteWatchService) Validate() error {
return nil
}
// Do executes the operation.
func (s *XpackWatcherExecuteWatchService) Do(ctx context.Context) (*XpackWatcherExecuteWatchResponse, error) {
func (s *XPackWatcherExecuteWatchService) Do(ctx context.Context) (*XPackWatcherExecuteWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -109,7 +118,7 @@ func (s *XpackWatcherExecuteWatchService) Do(ctx context.Context) (*XpackWatcher
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Method: "PUT",
Path: path,
Params: params,
Body: body,
@@ -119,31 +128,31 @@ func (s *XpackWatcherExecuteWatchService) Do(ctx context.Context) (*XpackWatcher
}
// Return operation response
ret := new(XpackWatcherExecuteWatchResponse)
ret := new(XPackWatcherExecuteWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherExecuteWatchResponse is the response of XpackWatcherExecuteWatchService.Do.
type XpackWatcherExecuteWatchResponse struct {
Id string `json:"_id"`
WatchRecord WatchRecord `json:"watch_record"`
// XPackWatcherExecuteWatchResponse is the response of XPackWatcherExecuteWatchService.Do.
type XPackWatcherExecuteWatchResponse struct {
Id string `json:"_id"`
WatchRecord *XPackWatchRecord `json:"watch_record"`
}
type WatchRecord struct {
type XPackWatchRecord struct {
WatchId string `json:"watch_id"`
Node string `json:"node"`
Messages []string `json:"messages"`
State string `json:"state"`
Status WatchRecordStatus `json:"status"`
Status *XPackWatchRecordStatus `json:"status"`
Input map[string]map[string]interface{} `json:"input"`
Condition map[string]map[string]interface{} `json:"condition"`
Result map[string]interface{} `json:"Result"`
}
type WatchRecordStatus struct {
type XPackWatchRecordStatus struct {
Version int `json:"version"`
State map[string]interface{} `json:"state"`
LastChecked string `json:"last_checked"`
+22 -21
View File
@@ -13,34 +13,35 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherGetWatchService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html.
type XpackWatcherGetWatchService struct {
// XPackWatcherGetWatchService retrieves a watch by its ID.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-get-watch.html.
type XPackWatcherGetWatchService struct {
client *Client
pretty bool
id string
}
// NewXpackWatcherGetWatchService creates a new XpackWatcherGetWatchService.
func NewXpackWatcherGetWatchService(client *Client) *XpackWatcherGetWatchService {
return &XpackWatcherGetWatchService{
// NewXPackWatcherGetWatchService creates a new XPackWatcherGetWatchService.
func NewXPackWatcherGetWatchService(client *Client) *XPackWatcherGetWatchService {
return &XPackWatcherGetWatchService{
client: client,
}
}
// Id is documented as: Watch ID.
func (s *XpackWatcherGetWatchService) Id(id string) *XpackWatcherGetWatchService {
// Id is ID of the watch to retrieve.
func (s *XPackWatcherGetWatchService) Id(id string) *XPackWatcherGetWatchService {
s.id = id
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherGetWatchService) Pretty(pretty bool) *XpackWatcherGetWatchService {
func (s *XPackWatcherGetWatchService) Pretty(pretty bool) *XPackWatcherGetWatchService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherGetWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherGetWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{id}", map[string]string{
"id": s.id,
@@ -52,13 +53,13 @@ func (s *XpackWatcherGetWatchService) buildURL() (string, url.Values, error) {
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *XpackWatcherGetWatchService) Validate() error {
func (s *XPackWatcherGetWatchService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
@@ -70,7 +71,7 @@ func (s *XpackWatcherGetWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherGetWatchService) Do(ctx context.Context) (*XpackWatcherGetWatchResponse, error) {
func (s *XPackWatcherGetWatchService) Do(ctx context.Context) (*XPackWatcherGetWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -93,28 +94,28 @@ func (s *XpackWatcherGetWatchService) Do(ctx context.Context) (*XpackWatcherGetW
}
// Return operation response
ret := new(XpackWatcherGetWatchResponse)
ret := new(XPackWatcherGetWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherGetWatchResponse is the response of XpackWatcherGetWatchService.Do.
type XpackWatcherGetWatchResponse struct {
Found bool `json:"found"`
Id string `json:"_id"`
Status WatchStatus `json:"status"`
Watch Watch `json:"watch"`
// XPackWatcherGetWatchResponse is the response of XPackWatcherGetWatchService.Do.
type XPackWatcherGetWatchResponse struct {
Found bool `json:"found"`
Id string `json:"_id"`
Status *XPackWatchStatus `json:"status"`
Watch *XPackWatch `json:"watch"`
}
type WatchStatus struct {
type XPackWatchStatus struct {
State map[string]interface{} `json:"state"`
Actions map[string]map[string]interface{} `json:"actions"`
Version int `json:"version"`
}
type Watch struct {
type XPackWatch struct {
Input map[string]map[string]interface{} `json:"input"`
Condition map[string]map[string]interface{} `json:"condition"`
Trigger map[string]map[string]interface{} `json:"trigger"`
+28 -41
View File
@@ -13,62 +13,57 @@ import (
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherPutWatchService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-put-watch.html.
type XpackWatcherPutWatchService struct {
// XPackWatcherPutWatchService either registers a new watch in Watcher
// or update an existing one.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-put-watch.html.
type XPackWatcherPutWatchService struct {
client *Client
pretty bool
id string
active *bool
masterTimeout string
bodyJson interface{}
bodyString string
body interface{}
}
// NewXpackWatcherPutWatchService creates a new XpackWatcherPutWatchService.
func NewXpackWatcherPutWatchService(client *Client) *XpackWatcherPutWatchService {
return &XpackWatcherPutWatchService{
// NewXPackWatcherPutWatchService creates a new XPackWatcherPutWatchService.
func NewXPackWatcherPutWatchService(client *Client) *XPackWatcherPutWatchService {
return &XPackWatcherPutWatchService{
client: client,
}
}
// Id is documented as: Watch ID.
func (s *XpackWatcherPutWatchService) Id(id string) *XpackWatcherPutWatchService {
// Id of the watch to upsert.
func (s *XPackWatcherPutWatchService) Id(id string) *XPackWatcherPutWatchService {
s.id = id
return s
}
// Active is documented as: Specify whether the watch is in/active by default.
func (s *XpackWatcherPutWatchService) Active(active bool) *XpackWatcherPutWatchService {
// Active specifies whether the watch is in/active by default.
func (s *XPackWatcherPutWatchService) Active(active bool) *XPackWatcherPutWatchService {
s.active = &active
return s
}
// MasterTimeout is documented as: Explicit operation timeout for connection to master node.
func (s *XpackWatcherPutWatchService) MasterTimeout(masterTimeout string) *XpackWatcherPutWatchService {
// MasterTimeout is an explicit operation timeout for connection to master node.
func (s *XPackWatcherPutWatchService) MasterTimeout(masterTimeout string) *XPackWatcherPutWatchService {
s.masterTimeout = masterTimeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherPutWatchService) Pretty(pretty bool) *XpackWatcherPutWatchService {
func (s *XPackWatcherPutWatchService) Pretty(pretty bool) *XPackWatcherPutWatchService {
s.pretty = pretty
return s
}
// BodyJson is documented as: The watch.
func (s *XpackWatcherPutWatchService) BodyJson(body interface{}) *XpackWatcherPutWatchService {
s.bodyJson = body
return s
}
// BodyString is documented as: The watch.
func (s *XpackWatcherPutWatchService) BodyString(body string) *XpackWatcherPutWatchService {
s.bodyString = body
// Body specifies the watch. Use a string or a type that will get serialized as JSON.
func (s *XPackWatcherPutWatchService) Body(body interface{}) *XPackWatcherPutWatchService {
s.body = body
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherPutWatchService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherPutWatchService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/watch/{id}", map[string]string{
"id": s.id,
@@ -80,7 +75,7 @@ func (s *XpackWatcherPutWatchService) buildURL() (string, url.Values, error) {
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.active != nil {
params.Set("active", fmt.Sprintf("%v", *s.active))
@@ -92,13 +87,13 @@ func (s *XpackWatcherPutWatchService) buildURL() (string, url.Values, error) {
}
// Validate checks if the operation is valid.
func (s *XpackWatcherPutWatchService) Validate() error {
func (s *XPackWatcherPutWatchService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
}
if s.bodyString == "" && s.bodyJson == nil {
invalid = append(invalid, "BodyJson")
if s.body == nil {
invalid = append(invalid, "Body")
}
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
@@ -107,7 +102,7 @@ func (s *XpackWatcherPutWatchService) Validate() error {
}
// Do executes the operation.
func (s *XpackWatcherPutWatchService) Do(ctx context.Context) (*XpackWatcherPutWatchResponse, error) {
func (s *XPackWatcherPutWatchService) Do(ctx context.Context) (*XPackWatcherPutWatchResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -119,33 +114,25 @@ func (s *XpackWatcherPutWatchService) Do(ctx context.Context) (*XpackWatcherPutW
return nil, err
}
// Setup HTTP request body
var body interface{}
if s.bodyJson != nil {
body = s.bodyJson
} else {
body = s.bodyString
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
Body: s.body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(XpackWatcherPutWatchResponse)
ret := new(XPackWatcherPutWatchResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherPutWatchResponse is the response of XpackWatcherPutWatchService.Do.
type XpackWatcherPutWatchResponse struct {
// XPackWatcherPutWatchResponse is the response of XPackWatcherPutWatchService.Do.
type XPackWatcherPutWatchResponse struct {
}
+14 -13
View File
@@ -10,45 +10,46 @@ import (
"net/url"
)
// XpackWatcherRestartService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-restart.html.
type XpackWatcherRestartService struct {
// XPackWatcherRestartService stops the starts the watcher service.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-restart.html.
type XPackWatcherRestartService struct {
client *Client
pretty bool
}
// NewXpackWatcherRestartService creates a new XpackWatcherRestartService.
func NewXpackWatcherRestartService(client *Client) *XpackWatcherRestartService {
return &XpackWatcherRestartService{
// NewXPackWatcherRestartService creates a new XPackWatcherRestartService.
func NewXPackWatcherRestartService(client *Client) *XPackWatcherRestartService {
return &XPackWatcherRestartService{
client: client,
}
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherRestartService) Pretty(pretty bool) *XpackWatcherRestartService {
func (s *XPackWatcherRestartService) Pretty(pretty bool) *XPackWatcherRestartService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherRestartService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherRestartService) buildURL() (string, url.Values, error) {
// Build URL path
path := "/_xpack/watcher/_restart"
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *XpackWatcherRestartService) Validate() error {
func (s *XPackWatcherRestartService) Validate() error {
return nil
}
// Do executes the operation.
func (s *XpackWatcherRestartService) Do(ctx context.Context) (*XpackWatcherRestartResponse, error) {
func (s *XPackWatcherRestartService) Do(ctx context.Context) (*XPackWatcherRestartResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -71,14 +72,14 @@ func (s *XpackWatcherRestartService) Do(ctx context.Context) (*XpackWatcherResta
}
// Return operation response
ret := new(XpackWatcherRestartResponse)
ret := new(XPackWatcherRestartResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherRestartResponse is the response of XpackWatcherRestartService.Do.
type XpackWatcherRestartResponse struct {
// XPackWatcherRestartResponse is the response of XPackWatcherRestartService.Do.
type XPackWatcherRestartResponse struct {
Acknowledged bool `json:"acknowledged"`
}
+14 -13
View File
@@ -10,45 +10,46 @@ import (
"net/url"
)
// XpackWatcherStartService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-start.html.
type XpackWatcherStartService struct {
// XPackWatcherStartService starts the watcher service if it is not already running.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-start.html.
type XPackWatcherStartService struct {
client *Client
pretty bool
}
// NewXpackWatcherStartService creates a new XpackWatcherStartService.
func NewXpackWatcherStartService(client *Client) *XpackWatcherStartService {
return &XpackWatcherStartService{
// NewXPackWatcherStartService creates a new XPackWatcherStartService.
func NewXPackWatcherStartService(client *Client) *XPackWatcherStartService {
return &XPackWatcherStartService{
client: client,
}
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherStartService) Pretty(pretty bool) *XpackWatcherStartService {
func (s *XPackWatcherStartService) Pretty(pretty bool) *XPackWatcherStartService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherStartService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherStartService) buildURL() (string, url.Values, error) {
// Build URL path
path := "/_xpack/watcher/_start"
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *XpackWatcherStartService) Validate() error {
func (s *XPackWatcherStartService) Validate() error {
return nil
}
// Do executes the operation.
func (s *XpackWatcherStartService) Do(ctx context.Context) (*XpackWatcherStartResponse, error) {
func (s *XPackWatcherStartService) Do(ctx context.Context) (*XPackWatcherStartResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -71,14 +72,14 @@ func (s *XpackWatcherStartService) Do(ctx context.Context) (*XpackWatcherStartRe
}
// Return operation response
ret := new(XpackWatcherStartResponse)
ret := new(XPackWatcherStartResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherStartResponse is the response of XpackWatcherStartService.Do.
type XpackWatcherStartResponse struct {
// XPackWatcherStartResponse is the response of XPackWatcherStartService.Do.
type XPackWatcherStartResponse struct {
Acknowledged bool `json:"acknowledged"`
}
+22 -27
View File
@@ -9,57 +9,51 @@ import (
"encoding/json"
"fmt"
"net/url"
"github.com/olivere/elastic/uritemplates"
)
// XpackWatcherStatsService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html.
type XpackWatcherStatsService struct {
// XPackWatcherStatsService returns the current watcher metrics.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-stats.html.
type XPackWatcherStatsService struct {
client *Client
pretty bool
metric string
emitStacktraces *bool
}
// NewXpackWatcherStatsService creates a new XpackWatcherStatsService.
func NewXpackWatcherStatsService(client *Client) *XpackWatcherStatsService {
return &XpackWatcherStatsService{
// NewXPackWatcherStatsService creates a new XPackWatcherStatsService.
func NewXPackWatcherStatsService(client *Client) *XPackWatcherStatsService {
return &XPackWatcherStatsService{
client: client,
}
}
// Metric is documented as: Controls what additional stat metrics should be include in the response.
func (s *XpackWatcherStatsService) Metric(metric string) *XpackWatcherStatsService {
// Metric controls what additional stat metrics should be include in the response.
func (s *XPackWatcherStatsService) Metric(metric string) *XPackWatcherStatsService {
s.metric = metric
return s
}
// EmitStacktraces is documented as: Emits stack traces of currently running watches.
func (s *XpackWatcherStatsService) EmitStacktraces(emitStacktraces bool) *XpackWatcherStatsService {
// EmitStacktraces, if enabled, emits stack traces of currently running watches.
func (s *XPackWatcherStatsService) EmitStacktraces(emitStacktraces bool) *XPackWatcherStatsService {
s.emitStacktraces = &emitStacktraces
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherStatsService) Pretty(pretty bool) *XpackWatcherStatsService {
func (s *XPackWatcherStatsService) Pretty(pretty bool) *XPackWatcherStatsService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherStatsService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherStatsService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_xpack/watcher/stats", map[string]string{
"metric": s.metric,
})
if err != nil {
return "", url.Values{}, err
}
path := "/_xpack/watcher/stats"
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.emitStacktraces != nil {
params.Set("emit_stacktraces", fmt.Sprintf("%v", *s.emitStacktraces))
@@ -71,12 +65,12 @@ func (s *XpackWatcherStatsService) buildURL() (string, url.Values, error) {
}
// Validate checks if the operation is valid.
func (s *XpackWatcherStatsService) Validate() error {
func (s *XPackWatcherStatsService) Validate() error {
return nil
}
// Do executes the operation.
func (s *XpackWatcherStatsService) Do(ctx context.Context) (*XpackWatcherStatsResponse, error) {
func (s *XPackWatcherStatsService) Do(ctx context.Context) (*XPackWatcherStatsResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -99,19 +93,20 @@ func (s *XpackWatcherStatsService) Do(ctx context.Context) (*XpackWatcherStatsRe
}
// Return operation response
ret := new(XpackWatcherStatsResponse)
ret := new(XPackWatcherStatsResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherStatsResponse is the response of XpackWatcherStatsService.Do.
type XpackWatcherStatsResponse struct {
Stats []WatcherStats `json:"stats"`
// XPackWatcherStatsResponse is the response of XPackWatcherStatsService.Do.
type XPackWatcherStatsResponse struct {
Stats []XPackWatcherStats `json:"stats"`
}
type WatcherStats struct {
// XPackWatcherStats represents the stats used in XPackWatcherStatsResponse.
type XPackWatcherStats struct {
WatcherState string `json:"watcher_state"`
WatchCount int `json:"watch_count"`
ExecutionThreadPool map[string]interface{} `json:"execution_thread_pool"`
+14 -13
View File
@@ -10,45 +10,46 @@ import (
"net/url"
)
// XpackWatcherStopService is documented at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stop.html.
type XpackWatcherStopService struct {
// XPackWatcherStopService stops the watcher service if it is running.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-stop.html.
type XPackWatcherStopService struct {
client *Client
pretty bool
}
// NewXpackWatcherStopService creates a new XpackWatcherStopService.
func NewXpackWatcherStopService(client *Client) *XpackWatcherStopService {
return &XpackWatcherStopService{
// NewXPackWatcherStopService creates a new XPackWatcherStopService.
func NewXPackWatcherStopService(client *Client) *XPackWatcherStopService {
return &XPackWatcherStopService{
client: client,
}
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *XpackWatcherStopService) Pretty(pretty bool) *XpackWatcherStopService {
func (s *XPackWatcherStopService) Pretty(pretty bool) *XPackWatcherStopService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *XpackWatcherStopService) buildURL() (string, url.Values, error) {
func (s *XPackWatcherStopService) buildURL() (string, url.Values, error) {
// Build URL path
path := "/_xpack/watcher/_stop"
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *XpackWatcherStopService) Validate() error {
func (s *XPackWatcherStopService) Validate() error {
return nil
}
// Do executes the operation.
func (s *XpackWatcherStopService) Do(ctx context.Context) (*XpackWatcherStopResponse, error) {
func (s *XPackWatcherStopService) Do(ctx context.Context) (*XPackWatcherStopResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
@@ -71,14 +72,14 @@ func (s *XpackWatcherStopService) Do(ctx context.Context) (*XpackWatcherStopResp
}
// Return operation response
ret := new(XpackWatcherStopResponse)
ret := new(XPackWatcherStopResponse)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// XpackWatcherStopResponse is the response of XpackWatcherStopService.Do.
type XpackWatcherStopResponse struct {
// XPackWatcherStopResponse is the response of XPackWatcherStopService.Do.
type XPackWatcherStopResponse struct {
Acknowledged bool `json:"acknowledged"`
}