[MM-16768] Add support for Elasticsearch v7 (#12537)

* [MM-16768] Add support for Elasticsearch v7

* Fix i18n

* Adds external services tracking to the telemetry

* Rebuild elasticsearch interface mock

* Rename diagnostics keys

* Fix merge change
This commit is contained in:
Miguel de la Cruz
2019-11-21 13:04:21 +01:00
committed by GitHub
parent 3a8fb53f3e
commit f7e93db512
279 changed files with 12110 additions and 3702 deletions

View File

@@ -52,6 +52,7 @@ const (
TRACK_PERMISSIONS_GENERAL = "permissions_general"
TRACK_PERMISSIONS_SYSTEM_SCHEME = "permissions_system_scheme"
TRACK_PERMISSIONS_TEAM_SCHEMES = "permissions_team_schemes"
TRACK_ELASTICSEARCH = "elasticsearch"
TRACK_ACTIVITY = "activity"
TRACK_LICENSE = "license"
@@ -72,6 +73,7 @@ func (a *App) sendDailyDiagnostics(override bool) {
a.trackPlugins()
a.trackServer()
a.trackPermissions()
a.trackElasticsearch()
}
}
@@ -861,3 +863,13 @@ func (a *App) trackPermissions() {
}
}
}
func (a *App) trackElasticsearch() {
data := map[string]interface{}{}
if a.Elasticsearch != nil && a.Elasticsearch.GetVersion() != 0 {
data["elasticsearch_server_version"] = a.Elasticsearch.GetVersion()
}
a.SendDiagnostic(TRACK_ELASTICSEARCH, data)
}

View File

@@ -23,7 +23,7 @@ import (
_ "github.com/prometheus/client_golang/prometheus"
_ "github.com/prometheus/client_golang/prometheus/promhttp"
_ "github.com/tylerb/graceful"
_ "gopkg.in/olivere/elastic.v5"
_ "gopkg.in/olivere/elastic.v6"
)
func main() {

View File

@@ -12,6 +12,7 @@ import (
type ElasticsearchInterface interface {
Start() *model.AppError
Stop() *model.AppError
GetVersion() int
IndexPost(post *model.Post, teamId string) *model.AppError
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams, page, perPage int) ([]string, model.PostSearchMatches, *model.AppError)
DeletePost(post *model.Post) *model.AppError

View File

@@ -4,9 +4,12 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import time "time"
import (
time "time"
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// ElasticsearchInterface is an autogenerated mock type for the ElasticsearchInterface type
type ElasticsearchInterface struct {
@@ -77,6 +80,20 @@ func (_m *ElasticsearchInterface) DeleteUser(user *model.User) *model.AppError {
return r0
}
// GetVersion provides a mock function with given fields:
func (_m *ElasticsearchInterface) GetVersion() int {
ret := _m.Called()
var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}
return r0
}
// IndexChannel provides a mock function with given fields: channel
func (_m *ElasticsearchInterface) IndexChannel(channel *model.Channel) *model.AppError {
ret := _m.Called(channel)

3
go.mod
View File

@@ -54,6 +54,7 @@ require (
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/muesli/smartcrop v0.3.0 // indirect
github.com/olekukonko/tablewriter v0.0.1 // indirect
github.com/olivere/elastic v6.2.23+incompatible // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/pborman/uuid v1.2.0
@@ -98,7 +99,7 @@ require (
gopkg.in/ini.v1 v1.48.0 // indirect
gopkg.in/mail.v2 v2.3.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/olivere/elastic.v5 v5.0.82
gopkg.in/olivere/elastic.v6 v6.2.23
gopkg.in/yaml.v2 v2.2.3
willnorris.com/go/imageproxy v0.9.0
)

10
go.sum
View File

@@ -79,8 +79,6 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -237,7 +235,6 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM=
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
@@ -292,6 +289,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olivere/elastic v6.2.23+incompatible h1:oRGUA/8fKcnkDcqLuwGb5YCzgbgEBo+Y9gamsWqZ0qU=
github.com/olivere/elastic v6.2.23+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
@@ -378,7 +377,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8=
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
@@ -587,8 +585,8 @@ gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk=
gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/olivere/elastic.v5 v5.0.82 h1:QH7ere4lvOAWnnOd0VLJ54W8LzExZszoGIRijnb1h2Y=
gopkg.in/olivere/elastic.v5 v5.0.82/go.mod h1:uhHoB4o3bvX5sorxBU29rPcmBQdV2Qfg0FBrx5D6pV0=
gopkg.in/olivere/elastic.v6 v6.2.23 h1:wDrXwXXecu8t/mTPbvMu8zONtTJA201IKq1RxSeEU38=
gopkg.in/olivere/elastic.v6 v6.2.23/go.mod h1:2cTT8Z+/LcArSWpCgvZqBgt3VOqXiy7v00w12Lz8bd4=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=

View File

@@ -3922,6 +3922,14 @@
"id": "ent.elasticsearch.start.create_bulk_processor_failed.app_error",
"translation": "Failed to create Elasticsearch bulk processor"
},
{
"id": "ent.elasticsearch.start.get_server_version.app_error",
"translation": "Failed to get Elasticsearch server version"
},
{
"id": "ent.elasticsearch.start.parse_server_version.app_error",
"translation": "Failed to parse Elasticsearch server version"
},
{
"id": "ent.elasticsearch.start.start_bulk_processor_failed.app_error",
"translation": "Failed to start Elasticsearch bulk processor"

View File

@@ -1,27 +0,0 @@
sudo: required
language: go
go:
- "1.10.x"
- "1.11.x"
- "1.12.x"
#- tip
env:
- GO111MODULE=on
- GO111MODULE=off
matrix:
allow_failures:
- go: tip
services:
- docker
before_install:
# Install netcat
- if [[ "$TRAVIS_OS_NAME" == "linux" && ! $(which nc) ]] ; then sudo apt-get install -y netcat ; fi
- sudo sysctl -w vm.max_map_count=262144
- docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:5.6.16 elasticsearch -Expack.security.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_ >& /dev/null &
- go get -u github.com/fortytw2/leaktest
- go get . ./aws/... ./config/... ./uritemplates/...
# Wait for Elasticsearch
- while ! nc -z localhost 9200; do sleep 1; done
install: true
script:
- go test -race -v . ./aws/... ./config/... ./uritemplates/...

View File

@@ -1,109 +0,0 @@
// 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"
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
// DeleteTemplateService deletes a search template. More information can
// be found at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html.
type DeleteTemplateService struct {
client *Client
pretty bool
id string
version *int
versionType string
}
// NewDeleteTemplateService creates a new DeleteTemplateService.
func NewDeleteTemplateService(client *Client) *DeleteTemplateService {
return &DeleteTemplateService{
client: client,
}
}
// Id is the template ID.
func (s *DeleteTemplateService) Id(id string) *DeleteTemplateService {
s.id = id
return s
}
// Version an explicit version number for concurrency control.
func (s *DeleteTemplateService) Version(version int) *DeleteTemplateService {
s.version = &version
return s
}
// VersionType specifies a version type.
func (s *DeleteTemplateService) VersionType(versionType string) *DeleteTemplateService {
s.versionType = versionType
return s
}
// buildURL builds the URL for the operation.
func (s *DeleteTemplateService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{
"id": s.id,
})
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.version != nil {
params.Set("version", fmt.Sprintf("%d", *s.version))
}
if s.versionType != "" {
params.Set("version_type", s.versionType)
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *DeleteTemplateService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
}
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
}
return nil
}
// Do executes the operation.
func (s *DeleteTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, 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, "DELETE", path, params, nil)
if err != nil {
return nil, err
}
// Return operation response
ret := new(AcknowledgedResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}

View File

@@ -1,259 +0,0 @@
// 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"
"fmt"
"net/http"
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
const (
FieldStatsClusterLevel = "cluster"
FieldStatsIndicesLevel = "indices"
)
// FieldStatsService allows finding statistical properties of a field without executing a search,
// but looking up measurements that are natively available in the Lucene index.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-field-stats.html
// for details
type FieldStatsService struct {
client *Client
pretty bool
level string
index []string
allowNoIndices *bool
expandWildcards string
fields []string
ignoreUnavailable *bool
bodyJson interface{}
bodyString string
}
// NewFieldStatsService creates a new FieldStatsService
func NewFieldStatsService(client *Client) *FieldStatsService {
return &FieldStatsService{
client: client,
index: make([]string, 0),
fields: make([]string, 0),
}
}
// Index is a list of index names; use `_all` or empty string to perform
// the operation on all indices.
func (s *FieldStatsService) Index(index ...string) *FieldStatsService {
s.index = append(s.index, index...)
return s
}
// AllowNoIndices indicates whether to ignore if a wildcard indices expression
// resolves into no concrete indices.
// (This includes `_all` string or when no indices have been specified).
func (s *FieldStatsService) AllowNoIndices(allowNoIndices bool) *FieldStatsService {
s.allowNoIndices = &allowNoIndices
return s
}
// ExpandWildcards indicates whether to expand wildcard expression to
// concrete indices that are open, closed or both.
func (s *FieldStatsService) ExpandWildcards(expandWildcards string) *FieldStatsService {
s.expandWildcards = expandWildcards
return s
}
// Fields is a list of fields for to get field statistics
// for (min value, max value, and more).
func (s *FieldStatsService) Fields(fields ...string) *FieldStatsService {
s.fields = append(s.fields, fields...)
return s
}
// IgnoreUnavailable is documented as: Whether specified concrete indices should be ignored when unavailable (missing or closed).
func (s *FieldStatsService) IgnoreUnavailable(ignoreUnavailable bool) *FieldStatsService {
s.ignoreUnavailable = &ignoreUnavailable
return s
}
// Level sets if stats should be returned on a per index level or on a cluster wide level;
// should be one of 'cluster' or 'indices'; defaults to former
func (s *FieldStatsService) Level(level string) *FieldStatsService {
s.level = level
return s
}
// ClusterLevel is a helper that sets Level to "cluster".
func (s *FieldStatsService) ClusterLevel() *FieldStatsService {
s.level = FieldStatsClusterLevel
return s
}
// IndicesLevel is a helper that sets Level to "indices".
func (s *FieldStatsService) IndicesLevel() *FieldStatsService {
s.level = FieldStatsIndicesLevel
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *FieldStatsService) Pretty(pretty bool) *FieldStatsService {
s.pretty = pretty
return s
}
// BodyJson is documented as: Field json objects containing the name and optionally a range to filter out indices result, that have results outside the defined bounds.
func (s *FieldStatsService) BodyJson(body interface{}) *FieldStatsService {
s.bodyJson = body
return s
}
// BodyString is documented as: Field json objects containing the name and optionally a range to filter out indices result, that have results outside the defined bounds.
func (s *FieldStatsService) BodyString(body string) *FieldStatsService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *FieldStatsService) buildURL() (string, url.Values, error) {
// Build URL
var err error
var path string
if len(s.index) > 0 {
path, err = uritemplates.Expand("/{index}/_field_stats", map[string]string{
"index": strings.Join(s.index, ","),
})
} else {
path = "/_field_stats"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
}
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
if len(s.fields) > 0 {
params.Set("fields", strings.Join(s.fields, ","))
}
if s.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
}
if s.level != "" {
params.Set("level", s.level)
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *FieldStatsService) Validate() error {
var invalid []string
if s.level != "" && (s.level != FieldStatsIndicesLevel && s.level != FieldStatsClusterLevel) {
invalid = append(invalid, "Level")
}
if len(invalid) != 0 {
return fmt.Errorf("missing or invalid required fields: %v", invalid)
}
return nil
}
// Do executes the operation.
func (s *FieldStatsService) Do(ctx context.Context) (*FieldStatsResponse, 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
}
// 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, "POST", path, params, body, http.StatusNotFound)
if err != nil {
return nil, err
}
// TODO(oe): Is 404 really a valid response here?
if res.StatusCode == http.StatusNotFound {
return &FieldStatsResponse{make(map[string]IndexFieldStats)}, nil
}
// Return operation response
ret := new(FieldStatsResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Request --
// FieldStatsRequest can be used to set up the body to be used in the
// Field Stats API.
type FieldStatsRequest struct {
Fields []string `json:"fields"`
IndexConstraints map[string]*FieldStatsConstraints `json:"index_constraints,omitempty"`
}
// FieldStatsConstraints is a constraint on a field.
type FieldStatsConstraints struct {
Min *FieldStatsComparison `json:"min_value,omitempty"`
Max *FieldStatsComparison `json:"max_value,omitempty"`
}
// FieldStatsComparison contain all comparison operations that can be used
// in FieldStatsConstraints.
type FieldStatsComparison struct {
Lte interface{} `json:"lte,omitempty"`
Lt interface{} `json:"lt,omitempty"`
Gte interface{} `json:"gte,omitempty"`
Gt interface{} `json:"gt,omitempty"`
}
// -- Response --
// FieldStatsResponse is the response body content
type FieldStatsResponse struct {
Indices map[string]IndexFieldStats `json:"indices,omitempty"`
}
// IndexFieldStats contains field stats for an index
type IndexFieldStats struct {
Fields map[string]FieldStats `json:"fields,omitempty"`
}
// FieldStats contains stats of an individual field
type FieldStats struct {
Type string `json:"type"`
MaxDoc int64 `json:"max_doc"`
DocCount int64 `json:"doc_count"`
Density int64 `json:"density"`
SumDocFrequeny int64 `json:"sum_doc_freq"`
SumTotalTermFrequency int64 `json:"sum_total_term_freq"`
Searchable bool `json:"searchable"`
Aggregatable bool `json:"aggregatable"`
MinValue interface{} `json:"min_value"`
MinValueAsString string `json:"min_value_as_string"`
MaxValue interface{} `json:"max_value"`
MaxValueAsString string `json:"max_value_as_string"`
}

View File

@@ -1,113 +0,0 @@
// 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"
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
// GetTemplateService reads a search template.
// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html.
type GetTemplateService struct {
client *Client
pretty bool
id string
version interface{}
versionType string
}
// NewGetTemplateService creates a new GetTemplateService.
func NewGetTemplateService(client *Client) *GetTemplateService {
return &GetTemplateService{
client: client,
}
}
// Id is the template ID.
func (s *GetTemplateService) Id(id string) *GetTemplateService {
s.id = id
return s
}
// Version is an explicit version number for concurrency control.
func (s *GetTemplateService) Version(version interface{}) *GetTemplateService {
s.version = version
return s
}
// VersionType is a specific version type.
func (s *GetTemplateService) VersionType(versionType string) *GetTemplateService {
s.versionType = versionType
return s
}
// buildURL builds the URL for the operation.
func (s *GetTemplateService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{
"id": s.id,
})
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.version != nil {
params.Set("version", fmt.Sprintf("%v", s.version))
}
if s.versionType != "" {
params.Set("version_type", s.versionType)
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *GetTemplateService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
}
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
}
return nil
}
// Do executes the operation and returns the template.
func (s *GetTemplateService) Do(ctx context.Context) (*GetTemplateResponse, 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, "GET", path, params, nil)
if err != nil {
return nil, err
}
// Return result
ret := new(GetTemplateResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
type GetTemplateResponse struct {
Template string `json:"template"`
}

View File

@@ -1,8 +0,0 @@
module gopkg.in/olivere/elastic.v5
require (
github.com/fortytw2/leaktest v1.2.0
github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5
github.com/pkg/errors v0.8.0
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9
)

View File

@@ -1,8 +0,0 @@
github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5 h1:0x4qcEHDpruK6ML/m/YSlFUUu0UpRD3I2PHsNCuGnyA=
github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 h1:hp2CYQUINdZMHdvTdXtPOY2ainKl4IoMcpAXEf2xj3Q=
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=

View File

@@ -1,312 +0,0 @@
// 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"
"fmt"
"net/url"
"strings"
"time"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
// NodesInfoService allows to retrieve one or more or all of the
// cluster nodes information.
// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html.
type NodesInfoService struct {
client *Client
pretty bool
nodeId []string
metric []string
flatSettings *bool
human *bool
}
// NewNodesInfoService creates a new NodesInfoService.
func NewNodesInfoService(client *Client) *NodesInfoService {
return &NodesInfoService{
client: client,
nodeId: []string{"_all"},
metric: []string{"_all"},
}
}
// NodeId is a list of node IDs or names to limit the returned information.
// Use "_local" to return information from the node you're connecting to,
// leave empty to get information from all nodes.
func (s *NodesInfoService) NodeId(nodeId ...string) *NodesInfoService {
s.nodeId = append(s.nodeId, nodeId...)
return s
}
// Metric is a list of metrics you wish returned. Leave empty to return all.
// Valid metrics are: settings, os, process, jvm, thread_pool, network,
// transport, http, and plugins.
func (s *NodesInfoService) Metric(metric ...string) *NodesInfoService {
s.metric = append(s.metric, metric...)
return s
}
// FlatSettings returns settings in flat format (default: false).
func (s *NodesInfoService) FlatSettings(flatSettings bool) *NodesInfoService {
s.flatSettings = &flatSettings
return s
}
// Human indicates whether to return time and byte values in human-readable format.
func (s *NodesInfoService) Human(human bool) *NodesInfoService {
s.human = &human
return s
}
// Pretty indicates whether to indent the returned JSON.
func (s *NodesInfoService) Pretty(pretty bool) *NodesInfoService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *NodesInfoService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_nodes/{node_id}/{metric}", map[string]string{
"node_id": strings.Join(s.nodeId, ","),
"metric": strings.Join(s.metric, ","),
})
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.flatSettings != nil {
params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings))
}
if s.human != nil {
params.Set("human", fmt.Sprintf("%v", *s.human))
}
if s.pretty {
params.Set("pretty", "1")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *NodesInfoService) Validate() error {
return nil
}
// Do executes the operation.
func (s *NodesInfoService) Do(ctx context.Context) (*NodesInfoResponse, 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, "GET", path, params, nil)
if err != nil {
return nil, err
}
// Return operation response
ret := new(NodesInfoResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// NodesInfoResponse is the response of NodesInfoService.Do.
type NodesInfoResponse struct {
ClusterName string `json:"cluster_name"`
Nodes map[string]*NodesInfoNode `json:"nodes"`
}
type NodesInfoNode struct {
// Name of the node, e.g. "Mister Fear"
Name string `json:"name"`
// TransportAddress, e.g. "127.0.0.1:9300"
TransportAddress string `json:"transport_address"`
// Host is the host name, e.g. "macbookair"
Host string `json:"host"`
// IP is the IP address, e.g. "192.168.1.2"
IP string `json:"ip"`
// Version is the Elasticsearch version running on the node, e.g. "1.4.3"
Version string `json:"version"`
// Build is the Elasticsearch build, e.g. "36a29a7"
Build string `json:"build"`
// HTTPAddress, e.g. "127.0.0.1:9200"
HTTPAddress string `json:"http_address"`
// HTTPSAddress, e.g. "127.0.0.1:9200"
HTTPSAddress string `json:"https_address"`
// Roles of the node, e.g. [master, ingest, data]
Roles []string `json:"roles"`
// Attributes of the node.
Attributes map[string]interface{} `json:"attributes"`
// Settings of the node, e.g. paths and pidfile.
Settings map[string]interface{} `json:"settings"`
// OS information, e.g. CPU and memory.
OS *NodesInfoNodeOS `json:"os"`
// Process information, e.g. max file descriptors.
Process *NodesInfoNodeProcess `json:"process"`
// JVM information, e.g. VM version.
JVM *NodesInfoNodeJVM `json:"jvm"`
// ThreadPool information.
ThreadPool *NodesInfoNodeThreadPool `json:"thread_pool"`
// Network information.
Network *NodesInfoNodeNetwork `json:"network"`
// Network information.
Transport *NodesInfoNodeTransport `json:"transport"`
// HTTP information.
HTTP *NodesInfoNodeHTTP `json:"http"`
// Plugins information.
Plugins []*NodesInfoNodePlugin `json:"plugins"`
}
type NodesInfoNodeOS struct {
RefreshInterval string `json:"refresh_interval"` // e.g. 1s
RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000
AvailableProcessors int `json:"available_processors"` // e.g. 4
// CPU information
CPU struct {
Vendor string `json:"vendor"` // e.g. Intel
Model string `json:"model"` // e.g. iMac15,1
MHz int `json:"mhz"` // e.g. 3500
TotalCores int `json:"total_cores"` // e.g. 4
TotalSockets int `json:"total_sockets"` // e.g. 4
CoresPerSocket int `json:"cores_per_socket"` // e.g. 16
CacheSizeInBytes int `json:"cache_size_in_bytes"` // e.g. 256
} `json:"cpu"`
// Mem information
Mem struct {
Total string `json:"total"` // e.g. 16gb
TotalInBytes int `json:"total_in_bytes"` // e.g. 17179869184
} `json:"mem"`
// Swap information
Swap struct {
Total string `json:"total"` // e.g. 1gb
TotalInBytes int `json:"total_in_bytes"` // e.g. 1073741824
} `json:"swap"`
}
type NodesInfoNodeProcess struct {
RefreshInterval string `json:"refresh_interval"` // e.g. 1s
RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000
ID int `json:"id"` // process id, e.g. 87079
MaxFileDescriptors int `json:"max_file_descriptors"` // e.g. 32768
Mlockall bool `json:"mlockall"` // e.g. false
}
type NodesInfoNodeJVM struct {
PID int `json:"pid"` // process id, e.g. 87079
Version string `json:"version"` // e.g. "1.8.0_25"
VMName string `json:"vm_name"` // e.g. "Java HotSpot(TM) 64-Bit Server VM"
VMVersion string `json:"vm_version"` // e.g. "25.25-b02"
VMVendor string `json:"vm_vendor"` // e.g. "Oracle Corporation"
StartTime time.Time `json:"start_time"` // e.g. "2015-01-03T15:18:30.982Z"
StartTimeInMillis int64 `json:"start_time_in_millis"`
// Mem information
Mem struct {
HeapInit string `json:"heap_init"` // e.g. 1gb
HeapInitInBytes int `json:"heap_init_in_bytes"`
HeapMax string `json:"heap_max"` // e.g. 4gb
HeapMaxInBytes int `json:"heap_max_in_bytes"`
NonHeapInit string `json:"non_heap_init"` // e.g. 2.4mb
NonHeapInitInBytes int `json:"non_heap_init_in_bytes"`
NonHeapMax string `json:"non_heap_max"` // e.g. 0b
NonHeapMaxInBytes int `json:"non_heap_max_in_bytes"`
DirectMax string `json:"direct_max"` // e.g. 4gb
DirectMaxInBytes int `json:"direct_max_in_bytes"`
} `json:"mem"`
GCCollectors []string `json:"gc_collectors"` // e.g. ["ParNew"]
MemoryPools []string `json:"memory_pools"` // e.g. ["Code Cache", "Metaspace"]
}
type NodesInfoNodeThreadPool struct {
Percolate *NodesInfoNodeThreadPoolSection `json:"percolate"`
Bench *NodesInfoNodeThreadPoolSection `json:"bench"`
Listener *NodesInfoNodeThreadPoolSection `json:"listener"`
Index *NodesInfoNodeThreadPoolSection `json:"index"`
Refresh *NodesInfoNodeThreadPoolSection `json:"refresh"`
Suggest *NodesInfoNodeThreadPoolSection `json:"suggest"`
Generic *NodesInfoNodeThreadPoolSection `json:"generic"`
Warmer *NodesInfoNodeThreadPoolSection `json:"warmer"`
Search *NodesInfoNodeThreadPoolSection `json:"search"`
Flush *NodesInfoNodeThreadPoolSection `json:"flush"`
Optimize *NodesInfoNodeThreadPoolSection `json:"optimize"`
Management *NodesInfoNodeThreadPoolSection `json:"management"`
Get *NodesInfoNodeThreadPoolSection `json:"get"`
Merge *NodesInfoNodeThreadPoolSection `json:"merge"`
Bulk *NodesInfoNodeThreadPoolSection `json:"bulk"`
Snapshot *NodesInfoNodeThreadPoolSection `json:"snapshot"`
}
type NodesInfoNodeThreadPoolSection struct {
Type string `json:"type"` // e.g. fixed
Min int `json:"min"` // e.g. 4
Max int `json:"max"` // e.g. 4
KeepAlive string `json:"keep_alive"` // e.g. "5m"
QueueSize interface{} `json:"queue_size"` // e.g. "1k" or -1
}
type NodesInfoNodeNetwork struct {
RefreshInterval string `json:"refresh_interval"` // e.g. 1s
RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000
PrimaryInterface struct {
Address string `json:"address"` // e.g. 192.168.1.2
Name string `json:"name"` // e.g. en0
MACAddress string `json:"mac_address"` // e.g. 11:22:33:44:55:66
} `json:"primary_interface"`
}
type NodesInfoNodeTransport struct {
BoundAddress []string `json:"bound_address"`
PublishAddress string `json:"publish_address"`
Profiles map[string]*NodesInfoNodeTransportProfile `json:"profiles"`
}
type NodesInfoNodeTransportProfile struct {
BoundAddress []string `json:"bound_address"`
PublishAddress string `json:"publish_address"`
}
type NodesInfoNodeHTTP struct {
BoundAddress []string `json:"bound_address"` // e.g. ["127.0.0.1:9200", "[fe80::1]:9200", "[::1]:9200"]
PublishAddress string `json:"publish_address"` // e.g. "127.0.0.1:9300"
MaxContentLength string `json:"max_content_length"` // e.g. "100mb"
MaxContentLengthInBytes int64 `json:"max_content_length_in_bytes"`
}
type NodesInfoNodePlugin struct {
Name string `json:"name"`
Description string `json:"description"`
Site bool `json:"site"`
JVM bool `json:"jvm"`
URL string `json:"url"` // e.g. /_plugin/dummy/
}

View File

@@ -1,145 +0,0 @@
// 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"
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
// PutTemplateService creates or updates a search template.
// The documentation can be found at
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html.
type PutTemplateService struct {
client *Client
pretty bool
id string
opType string
version *int
versionType string
bodyJson interface{}
bodyString string
}
// NewPutTemplateService creates a new PutTemplateService.
func NewPutTemplateService(client *Client) *PutTemplateService {
return &PutTemplateService{
client: client,
}
}
// Id is the template ID.
func (s *PutTemplateService) Id(id string) *PutTemplateService {
s.id = id
return s
}
// OpType is an explicit operation type.
func (s *PutTemplateService) OpType(opType string) *PutTemplateService {
s.opType = opType
return s
}
// Version is an explicit version number for concurrency control.
func (s *PutTemplateService) Version(version int) *PutTemplateService {
s.version = &version
return s
}
// VersionType is a specific version type.
func (s *PutTemplateService) VersionType(versionType string) *PutTemplateService {
s.versionType = versionType
return s
}
// BodyJson is the document as a JSON serializable object.
func (s *PutTemplateService) BodyJson(body interface{}) *PutTemplateService {
s.bodyJson = body
return s
}
// BodyString is the document as a string.
func (s *PutTemplateService) BodyString(body string) *PutTemplateService {
s.bodyString = body
return s
}
// buildURL builds the URL for the operation.
func (s *PutTemplateService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{
"id": s.id,
})
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.version != nil {
params.Set("version", fmt.Sprintf("%d", *s.version))
}
if s.versionType != "" {
params.Set("version_type", s.versionType)
}
if s.opType != "" {
params.Set("op_type", s.opType)
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *PutTemplateService) Validate() error {
var invalid []string
if s.id == "" {
invalid = append(invalid, "Id")
}
if s.bodyString == "" && s.bodyJson == nil {
invalid = append(invalid, "BodyJson")
}
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
}
return nil
}
// Do executes the operation.
func (s *PutTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, 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
}
// 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, "PUT", path, params, body)
if err != nil {
return nil, err
}
// Return operation response
ret := new(AcknowledgedResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}

View File

@@ -1,3 +0,0 @@
#!/bin/sh
VERSION=${VERSION:=5.6.16}
docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/etc:/usr/share/elasticsearch/config" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:$VERSION elasticsearch -Expack.security.enabled=false -Expack.ml.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true

View File

@@ -1,89 +0,0 @@
// 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
// IndicesQuery can be used when executed across multiple indices, allowing
// to have a query that executes only when executed on an index that matches
// a specific list of indices, and another query that executes when it is
// executed on an index that does not match the listed indices.
//
// For more details, see
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-indices-query.html
type IndicesQuery struct {
query Query
indices []string
noMatchQueryType string
noMatchQuery Query
queryName string
}
// NewIndicesQuery creates and initializes a new indices query.
func NewIndicesQuery(query Query, indices ...string) *IndicesQuery {
return &IndicesQuery{
query: query,
indices: indices,
}
}
// NoMatchQuery sets the query to use when it executes on an index that
// does not match the indices provided.
func (q *IndicesQuery) NoMatchQuery(query Query) *IndicesQuery {
q.noMatchQuery = query
return q
}
// NoMatchQueryType sets the no match query which can be either all or none.
func (q *IndicesQuery) NoMatchQueryType(typ string) *IndicesQuery {
q.noMatchQueryType = typ
return q
}
// QueryName sets the query name for the filter.
func (q *IndicesQuery) QueryName(queryName string) *IndicesQuery {
q.queryName = queryName
return q
}
// Source returns JSON for the function score query.
func (q *IndicesQuery) Source() (interface{}, error) {
// {
// "indices" : {
// "indices" : ["index1", "index2"],
// "query" : {
// "term" : { "tag" : "wow" }
// },
// "no_match_query" : {
// "term" : { "tag" : "kow" }
// }
// }
// }
source := make(map[string]interface{})
params := make(map[string]interface{})
source["indices"] = params
params["indices"] = q.indices
src, err := q.query.Source()
if err != nil {
return nil, err
}
params["query"] = src
if q.noMatchQuery != nil {
src, err := q.noMatchQuery.Source()
if err != nil {
return nil, err
}
params["no_match_query"] = src
} else if q.noMatchQueryType != "" {
params["no_match_query"] = q.noMatchQueryType
}
if q.queryName != "" {
params["_name"] = q.queryName
}
return source, nil
}

View File

@@ -1,217 +0,0 @@
// 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 (
"encoding/json"
"strings"
)
// SearchRequest combines a search request and its
// query details (see SearchSource).
// It is used in combination with MultiSearch.
type SearchRequest struct {
searchType string
indices []string
types []string
routing *string
preference *string
requestCache *bool
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
scroll string
source interface{}
}
// NewSearchRequest creates a new search request.
func NewSearchRequest() *SearchRequest {
return &SearchRequest{}
}
// SearchRequest must be one of dfs_query_then_fetch, query_then_fetch
// or query_and_fetch (deprecated in 5.3).
func (r *SearchRequest) SearchType(searchType string) *SearchRequest {
r.searchType = searchType
return r
}
// SearchTypeDfsQueryThenFetch sets search type to dfs_query_then_fetch.
func (r *SearchRequest) SearchTypeDfsQueryThenFetch() *SearchRequest {
return r.SearchType("dfs_query_then_fetch")
}
// SearchTypeQueryThenFetch sets search type to query_then_fetch.
func (r *SearchRequest) SearchTypeQueryThenFetch() *SearchRequest {
return r.SearchType("query_then_fetch")
}
// SearchTypeQueryAndFetch sets search type to query_and_fetch which
// was deprecated in 5.3.
func (r *SearchRequest) SearchTypeQueryAndFetch() *SearchRequest {
return r.SearchType("query_and_fetch")
}
func (r *SearchRequest) Index(indices ...string) *SearchRequest {
r.indices = append(r.indices, indices...)
return r
}
func (r *SearchRequest) HasIndices() bool {
return len(r.indices) > 0
}
func (r *SearchRequest) Type(types ...string) *SearchRequest {
r.types = append(r.types, types...)
return r
}
func (r *SearchRequest) Routing(routing string) *SearchRequest {
r.routing = &routing
return r
}
func (r *SearchRequest) Routings(routings ...string) *SearchRequest {
if routings != nil {
routings := strings.Join(routings, ",")
r.routing = &routings
} else {
r.routing = nil
}
return r
}
func (r *SearchRequest) Preference(preference string) *SearchRequest {
r.preference = &preference
return r
}
func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest {
r.requestCache = &requestCache
return r
}
// IgnoreUnavailable indicates whether specified concrete indices should be
// ignored when unavailable (missing or closed).
func (s *SearchRequest) IgnoreUnavailable(ignoreUnavailable bool) *SearchRequest {
s.ignoreUnavailable = &ignoreUnavailable
return s
}
// AllowNoIndices indicates whether to ignore if a wildcard indices
// expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified).
func (s *SearchRequest) AllowNoIndices(allowNoIndices bool) *SearchRequest {
s.allowNoIndices = &allowNoIndices
return s
}
// ExpandWildcards indicates whether to expand wildcard expression to
// concrete indices that are open, closed or both.
func (s *SearchRequest) ExpandWildcards(expandWildcards string) *SearchRequest {
s.expandWildcards = expandWildcards
return s
}
func (r *SearchRequest) Scroll(scroll string) *SearchRequest {
r.scroll = scroll
return r
}
func (r *SearchRequest) SearchSource(searchSource *SearchSource) *SearchRequest {
return r.Source(searchSource)
}
func (r *SearchRequest) Source(source interface{}) *SearchRequest {
r.source = source
return r
}
// header is used e.g. by MultiSearch to get information about the search header
// of one SearchRequest.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-multi-search.html
func (r *SearchRequest) header() interface{} {
h := make(map[string]interface{})
if r.searchType != "" {
h["search_type"] = r.searchType
}
switch len(r.indices) {
case 0:
case 1:
h["index"] = r.indices[0]
default:
h["indices"] = r.indices
}
switch len(r.types) {
case 0:
case 1:
h["type"] = r.types[0]
default:
h["types"] = r.types
}
if r.routing != nil && *r.routing != "" {
h["routing"] = *r.routing
}
if r.preference != nil && *r.preference != "" {
h["preference"] = *r.preference
}
if r.requestCache != nil {
h["request_cache"] = *r.requestCache
}
if r.ignoreUnavailable != nil {
h["ignore_unavailable"] = *r.ignoreUnavailable
}
if r.allowNoIndices != nil {
h["allow_no_indices"] = *r.allowNoIndices
}
if r.expandWildcards != "" {
h["expand_wildcards"] = r.expandWildcards
}
if r.scroll != "" {
h["scroll"] = r.scroll
}
return h
}
// Body allows to access the search body of the request, as generated by the DSL.
// Notice that Body is read-only. You must not change the request body.
//
// Body is used e.g. by MultiSearch to get information about the search body
// of one SearchRequest.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-multi-search.html
func (r *SearchRequest) Body() (string, error) {
switch t := r.source.(type) {
default:
body, err := json.Marshal(r.source)
if err != nil {
return "", err
}
return string(body), nil
case *SearchSource:
src, err := t.Source()
if err != nil {
return "", err
}
body, err := json.Marshal(src)
if err != nil {
return "", err
}
return string(body), nil
case json.RawMessage:
return string(t), nil
case *json.RawMessage:
return string(*t), nil
case string:
return t, nil
case *string:
if t != nil {
return *t, nil
}
return "{}", nil
}
}

View File

@@ -1,158 +0,0 @@
// 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"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
)
// SuggestService returns suggestions for text.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html.
type SuggestService struct {
client *Client
pretty bool
routing string
preference string
index []string
suggesters []Suggester
}
// NewSuggestService creates a new instance of SuggestService.
func NewSuggestService(client *Client) *SuggestService {
builder := &SuggestService{
client: client,
}
return builder
}
// Index adds one or more indices to use for the suggestion request.
func (s *SuggestService) Index(index ...string) *SuggestService {
s.index = append(s.index, index...)
return s
}
// Pretty asks Elasticsearch to return indented JSON.
func (s *SuggestService) Pretty(pretty bool) *SuggestService {
s.pretty = pretty
return s
}
// Routing specifies the routing value.
func (s *SuggestService) Routing(routing string) *SuggestService {
s.routing = routing
return s
}
// Preference specifies the node or shard the operation should be
// performed on (default: random).
func (s *SuggestService) Preference(preference string) *SuggestService {
s.preference = preference
return s
}
// Suggester adds a suggester to the request.
func (s *SuggestService) Suggester(suggester Suggester) *SuggestService {
s.suggesters = append(s.suggesters, suggester)
return s
}
// buildURL builds the URL for the operation.
func (s *SuggestService) buildURL() (string, url.Values, error) {
var err error
var path string
if len(s.index) > 0 {
path, err = uritemplates.Expand("/{index}/_suggest", map[string]string{
"index": strings.Join(s.index, ","),
})
} else {
path = "/_suggest"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
}
if s.routing != "" {
params.Set("routing", s.routing)
}
if s.preference != "" {
params.Set("preference", s.preference)
}
return path, params, nil
}
// Do executes the request.
func (s *SuggestService) Do(ctx context.Context) (SuggestResult, error) {
path, params, err := s.buildURL()
if err != nil {
return nil, err
}
// Set body
body := make(map[string]interface{})
for _, s := range s.suggesters {
src, err := s.Source(false)
if err != nil {
return nil, err
}
body[s.Name()] = src
}
// Get response
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
if err != nil {
return nil, err
}
// There is a _shard object that cannot be deserialized.
// So we use json.RawMessage instead.
var suggestions map[string]*json.RawMessage
if err := s.client.decoder.Decode(res.Body, &suggestions); err != nil {
return nil, err
}
ret := make(SuggestResult)
for name, result := range suggestions {
if name != "_shards" {
var sug []Suggestion
if err := s.client.decoder.Decode(*result, &sug); err != nil {
return nil, err
}
ret[name] = sug
}
}
return ret, nil
}
// SuggestResult is the outcome of SuggestService.Do.
type SuggestResult map[string][]Suggestion
// Suggestion is a single suggester outcome.
type Suggestion struct {
Text string `json:"text"`
Offset int `json:"offset"`
Length int `json:"length"`
Options []suggestionOption `json:"options"`
}
type suggestionOption struct {
Text string `json:"text"`
Score float64 `json:"score"`
Freq int `json:"freq"`
Payload interface{} `json:"payload"`
CollateMatch bool `json:"collate_match"`
}

View File

@@ -1,181 +0,0 @@
// 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
// FuzzyCompletionSuggester is a CompletionSuggester that allows fuzzy
// completion.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html
// for details, and
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html#fuzzy
// for details about the fuzzy completion suggester.
//
// @Deprecated Use CompletionSuggester with FuzzyOptions instead.
type FuzzyCompletionSuggester struct {
Suggester
name string
text string
field string
analyzer string
size *int
shardSize *int
contextQueries []SuggesterContextQuery
fuzziness interface{}
fuzzyTranspositions *bool
fuzzyMinLength *int
fuzzyPrefixLength *int
unicodeAware *bool
}
// Fuzziness defines the fuzziness which is used in FuzzyCompletionSuggester.
type Fuzziness struct {
}
// Creates a new completion suggester.
func NewFuzzyCompletionSuggester(name string) *FuzzyCompletionSuggester {
return &FuzzyCompletionSuggester{
name: name,
contextQueries: make([]SuggesterContextQuery, 0),
}
}
func (q *FuzzyCompletionSuggester) Name() string {
return q.name
}
func (q *FuzzyCompletionSuggester) Text(text string) *FuzzyCompletionSuggester {
q.text = text
return q
}
func (q *FuzzyCompletionSuggester) Field(field string) *FuzzyCompletionSuggester {
q.field = field
return q
}
func (q *FuzzyCompletionSuggester) Analyzer(analyzer string) *FuzzyCompletionSuggester {
q.analyzer = analyzer
return q
}
func (q *FuzzyCompletionSuggester) Size(size int) *FuzzyCompletionSuggester {
q.size = &size
return q
}
func (q *FuzzyCompletionSuggester) ShardSize(shardSize int) *FuzzyCompletionSuggester {
q.shardSize = &shardSize
return q
}
func (q *FuzzyCompletionSuggester) ContextQuery(query SuggesterContextQuery) *FuzzyCompletionSuggester {
q.contextQueries = append(q.contextQueries, query)
return q
}
func (q *FuzzyCompletionSuggester) ContextQueries(queries ...SuggesterContextQuery) *FuzzyCompletionSuggester {
q.contextQueries = append(q.contextQueries, queries...)
return q
}
// Fuzziness defines the strategy used to describe what "fuzzy" actually
// means for the suggester, e.g. 1, 2, "0", "1..2", ">4", or "AUTO".
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/common-options.html#fuzziness
// for a detailed description.
func (q *FuzzyCompletionSuggester) Fuzziness(fuzziness interface{}) *FuzzyCompletionSuggester {
q.fuzziness = fuzziness
return q
}
func (q *FuzzyCompletionSuggester) FuzzyTranspositions(fuzzyTranspositions bool) *FuzzyCompletionSuggester {
q.fuzzyTranspositions = &fuzzyTranspositions
return q
}
func (q *FuzzyCompletionSuggester) FuzzyMinLength(minLength int) *FuzzyCompletionSuggester {
q.fuzzyMinLength = &minLength
return q
}
func (q *FuzzyCompletionSuggester) FuzzyPrefixLength(prefixLength int) *FuzzyCompletionSuggester {
q.fuzzyPrefixLength = &prefixLength
return q
}
func (q *FuzzyCompletionSuggester) UnicodeAware(unicodeAware bool) *FuzzyCompletionSuggester {
q.unicodeAware = &unicodeAware
return q
}
// Creates the source for the completion suggester.
func (q *FuzzyCompletionSuggester) Source(includeName bool) (interface{}, error) {
cs := &completionSuggesterRequest{}
if q.text != "" {
cs.Text = q.text
}
suggester := make(map[string]interface{})
cs.Completion = suggester
if q.analyzer != "" {
suggester["analyzer"] = q.analyzer
}
if q.field != "" {
suggester["field"] = q.field
}
if q.size != nil {
suggester["size"] = *q.size
}
if q.shardSize != nil {
suggester["shard_size"] = *q.shardSize
}
switch len(q.contextQueries) {
case 0:
case 1:
src, err := q.contextQueries[0].Source()
if err != nil {
return nil, err
}
suggester["context"] = src
default:
var ctxq []interface{}
for _, query := range q.contextQueries {
src, err := query.Source()
if err != nil {
return nil, err
}
ctxq = append(ctxq, src)
}
suggester["context"] = ctxq
}
// Fuzzy Completion Suggester fields
fuzzy := make(map[string]interface{})
suggester["fuzzy"] = fuzzy
if q.fuzziness != nil {
fuzzy["fuzziness"] = q.fuzziness
}
if q.fuzzyTranspositions != nil {
fuzzy["transpositions"] = *q.fuzzyTranspositions
}
if q.fuzzyMinLength != nil {
fuzzy["min_length"] = *q.fuzzyMinLength
}
if q.fuzzyPrefixLength != nil {
fuzzy["prefix_length"] = *q.fuzzyPrefixLength
}
if q.unicodeAware != nil {
fuzzy["unicode_aware"] = *q.unicodeAware
}
if !includeName {
return cs, nil
}
source := make(map[string]interface{})
source[q.name] = cs
return source, nil
}

38
vendor/gopkg.in/olivere/elastic.v6/.fossa.yml generated vendored Normal file
View File

@@ -0,0 +1,38 @@
# Generated by FOSSA CLI (https://github.com/fossas/fossa-cli)
# Visit https://fossa.io to learn more
version: 1
cli:
server: https://app.fossa.io
fetcher: git
project: git@github.com:olivere/elastic.git
analyze:
modules:
- name: github.com/olivere/elastic
path: .
target: github.com/olivere/elastic
type: go
- name: github.com/olivere/elastic/config
path: ./config
target: github.com/olivere/elastic/config
type: go
- name: github.com/olivere/elastic/uritemplates
path: ./uritemplates
target: github.com/olivere/elastic/uritemplates
type: go
- name: github.com/olivere/elastic/trace/opencensus
path: ./trace/opencensus
target: github.com/olivere/elastic/trace/opencensus
type: go
- name: github.com/olivere/elastic/trace/opentracing
path: ./trace/opentracing
target: github.com/olivere/elastic/trace/opentracing
type: go
- name: github.com/olivere/elastic/aws
path: ./aws
target: github.com/olivere/elastic/aws
type: go
- name: github.com/olivere/elastic/aws/v4
path: ./aws/v4
target: github.com/olivere/elastic/aws/v4
type: go

View File

@@ -22,11 +22,13 @@ _testmain.go
*.exe
/.vscode/
/.idea/
/debug.test
/generator
/cluster-test/cluster-test
/cluster-test/*.log
/cluster-test/es-chaos-monkey
/go.sum
/spec
/tmp
/CHANGELOG-3.0.html

78
vendor/gopkg.in/olivere/elastic.v6/.golangci.yml generated vendored Normal file
View File

@@ -0,0 +1,78 @@
run:
# 30min deadline
deadline: 30m
# Fail when any changes to go.mod are needed
# (enable after Go modules are introduced)
#modules-download-mode: readonly
# Skip certain directories
skip-dirs:
- node_modules$
# Skip certain auto-generated files
skip-files:
- ".*\\.pb\\.go$"
linters-settings:
errcheck:
check-blank: false
ignore: fmt:.*,io/ioutil:^Read.*,os:^Write.*,net/http:^ParseForm.*,github.com/go-kit/kit/log:^Log.*,github.com/go-kit/kit/log/level:^Log.*
govet:
check-shadowing: false
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
- (github.com/go-kit/kit/log.Logger).Log
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 30
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
- github.com/davecgh/go-spew/spew
misspell:
locale: US
lll:
line-length: 120
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/olivere/elastic
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc
- importShadow
linters:
enable-all: true
disable:
- maligned
- prealloc
- gochecknoglobals
- gochecknoinits
- gocyclo
- dupl
- lll
- goconst
issues:
exclude-rules:
- linters:
- lll
source: '^//go:generate '
- path: sage/
text: "ALL_CAPS|don't use underscores in Go names|struct field.*should be"

33
vendor/gopkg.in/olivere/elastic.v6/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,33 @@
sudo: required
language: go
go:
- "1.11.x"
- "1.12.x"
- tip
matrix:
allow_failures:
- go: tip
env:
- GO111MODULE=on
- GO111MODULE=off
addons:
ssh_known_hosts: github.com
apt:
update: true
packages:
- docker-ce
services:
- docker
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" && ! $(which nc) ]] ; then sudo apt-get install -y netcat ; fi
- sudo sysctl -w vm.max_map_count=262144
- docker-compose pull
- docker-compose up -d
- go get -u github.com/google/go-cmp/cmp
- go get -u github.com/fortytw2/leaktest
- go get . ./aws/... ./config/... ./trace/... ./uritemplates/...
- while ! nc -z localhost 9200; do sleep 1; done
- while ! nc -z localhost 9210; do sleep 1; done
install: true # ignore the go get -t -v ./...
script:
- go test -race -v . ./aws/... ./config/... ./trace/... ./uritemplates/...

18
vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-6.0.md generated vendored Normal file
View File

@@ -0,0 +1,18 @@
# Changes from 5.0 to 6.0
See [breaking changes](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-6.0.html).
## _all removed
6.0 has removed support for the `_all` field.
## Boolean values coerced
Only use `true` or `false` for boolean values, not `0` or `1` or `on` or `off`.
## Single Type Indices
Notice that 6.0 and future versions will default to single type indices, i.e. you may not use multiple types when e.g. adding an index with a mapping.
See [here for details](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html#_what_are_mapping_types).

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.
@@ -36,5 +36,5 @@ following things in mind before submitting your pull request:
## Additional Resources
* [GitHub documentation](http://help.github.com/)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
* [GitHub documentation](https://help.github.com/)
* [GitHub pull request documentation](https://help.github.com/en/articles/creating-a-pull-request)

185
vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTORS generated vendored Normal file
View File

@@ -0,0 +1,185 @@
# This is a list of people who have contributed code
# to the Elastic repository.
#
# It is just my small "thank you" to all those that helped
# making Elastic what it is.
#
# Please keep this list sorted.
0x6875790d0a [@huydx](https://github.com/huydx)
Aaron Tami [@aarontami](https://github.com/aarontami)
Adam Alix [@adamalix](https://github.com/adamalix)
Adam Weiner [@adamweiner](https://github.com/adamweiner)
Adrian Lungu [@AdrianLungu](https://github.com/AdrianLungu)
alehano [@alehano](https://github.com/alehano)
Alejandro Carstens [@alejandro-carstens](https://github.com/alejandro-carstens)
Alex [@akotlar](https://github.com/akotlar)
Alexander Sack [@asac](https://github.com/asac)
Alexandre Olivier [@aliphen](https://github.com/aliphen)
Alexey Sharov [@nizsheanez](https://github.com/nizsheanez)
Anders [@ANerd](https://github.com/ANerd)
AndreKR [@AndreKR](https://github.com/AndreKR)
André Bierlein [@ligustah](https://github.com/ligustah)
Andrew Dunham [@andrew-d](https://github.com/andrew-d)
Andrew Gaul [@andrewgaul](https://github.com/andrewgaul)
Andy Walker [@alaska](https://github.com/alaska)
Arquivei [@arquivei](https://github.com/arquivei)
Artemiy Elozhenko [@artezh](https://github.com/artezh)
arthurgustin [@arthurgustin](https://github.com/arthurgustin)
Bas van Dijk [@basvandijk](https://github.com/basvandijk)
Benjamin Fernandes [@LotharSee](https://github.com/LotharSee)
Benjamin Zarzycki [@kf6nux](https://github.com/kf6nux)
Björn Gerdau [@kernle32dll](https://github.com/kernle32dll)
Boris Popovschi [@Zyqsempai](https://github.com/Zyqsempai)
Bowei Xu [@vancexu](https://github.com/vancexu)
Braden Bassingthwaite [@bbassingthwaite-va](https://github.com/bbassingthwaite-va)
Brady Love [@bradylove](https://github.com/bradylove)
Bryan Conklin [@bmconklin](https://github.com/bmconklin)
Bruce Zhou [@brucez-isell](https://github.com/brucez-isell)
Carl Dunham [@carldunham](https://github.com/carldunham)
Carl Johan Gustavsson [@cjgu](https://github.com/cjgu)
Cat [@cat-turner](https://github.com/cat-turner)
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)
Chris Duncan [@veqryn](https://github.com/veqryn)
Chris Ludden [@cludden](https://github.com/cludden)
Christophe Courtaut [@kri5](https://github.com/kri5)
cmitchell [@cmitchell](https://github.com/cmitchell)
Connor Peet [@connor4312](https://github.com/connor4312)
Conrad Pankoff [@deoxxa](https://github.com/deoxxa)
Corey Scott [@corsc](https://github.com/corsc)
Chris Petersen [@ex-nerd](https://github.com/ex-nerd)
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)
Diego Becciolini [@itizir](https://github.com/itizir)
Dwayne Schultz [@myshkin5](https://github.com/myshkin5)
Elliot Williams [@elliotwms](https://github.com/elliotwms)
Ellison Leão [@ellisonleao](https://github.com/ellisonleao)
Erik Grinaker [@erikgrinaker](https://github.com/erikgrinaker)
Erwin [@eticzon](https://github.com/eticzon)
Etienne Lafarge [@elafarge](https://github.com/elafarge)
Eugene Egorov [@EugeneEgorov](https://github.com/EugeneEgorov)
Evan Shaw [@edsrzf](https://github.com/edsrzf)
Fanfan [@wenpos](https://github.com/wenpos)
Faolan C-P [@fcheslack](https://github.com/fcheslack)
Filip Tepper [@filiptepper](https://github.com/filiptepper)
Garrett Kelley [@GarrettKelley](https://github.com/GarrettKelley)
Gaspard Douady [@plopik](https://github.com/plopik)
Gaylord Aulke [@blafasel42](https://github.com/blafasel42)
Gerhard Häring [@ghaering](https://github.com/ghaering)
gregoryfranklin [@gregoryfranklin](https://github.com/gregoryfranklin)
Guilherme Silveira [@guilherme-santos](https://github.com/guilherme-santos)
Guillaume J. Charmes [@creack](https://github.com/creack)
Guiseppe [@gm42](https://github.com/gm42)
Han Yu [@MoonighT](https://github.com/MoonighT)
Harmen [@alicebob](https://github.com/alicebob)
Harrison Wright [@wright8191](https://github.com/wright8191)
Henry Clifford [@hcliff](https://github.com/hcliff)
Igor Dubinskiy [@idubinskiy](https://github.com/idubinskiy)
initialcontext [@initialcontext](https://github.com/initialcontext)
Isaac Saldana [@isaldana](https://github.com/isaldana)
J Barkey Wolf [@jjhbw](https://github.com/jjhbw)
Jack Lindamood [@cep21](https://github.com/cep21)
Jacob [@jdelgad](https://github.com/jdelgad)
Jan Düpmeier [@jduepmeier](https://github.com/jduepmeier)
Jayme Rotsaert [@jrots](https://github.com/jrots)
Jean-Alexandre Beaumont [@Enteris](https://github.com/Enteris)
Jean-François Roche [@jfroche](https://github.com/jfroche)
Jeff Rand [@jeffrand](https://github.com/jeffrand)
Jeremy Canady [@jrmycanady](https://github.com/jrmycanady)
Jérémie Vexiau [@texvex](https://github.com/texvex)
Jesper Bränn [@Yopi](https://github.com/Yopi)
Jim Berlage [@jimberlage](https://github.com/jimberlage)
Joe Buck [@four2five](https://github.com/four2five)
John Barker [@j16r](https://github.com/j16r)
John Goodall [@jgoodall](https://github.com/jgoodall)
John Stanford [@jxstanford](https://github.com/jxstanford)
Jonas Groenaas Drange [@semafor](https://github.com/semafor)
Josef Fröhle [@Dexus](https://github.com/Dexus)
José Martínez [@xose](https://github.com/xose)
Josh Chorlton [@jchorl](https://github.com/jchorl)
Jpnock [@Jpnock](https://github.com/Jpnock)
jun [@coseyo](https://github.com/coseyo)
Junpei Tsuji [@jun06t](https://github.com/jun06t)
kartlee [@kartlee](https://github.com/kartlee)
Keith Hatton [@khatton-ft](https://github.com/khatton-ft)
kel [@liketic](https://github.com/liketic)
Kenta SUZUKI [@suzuken](https://github.com/suzuken)
Kevin Mulvey [@kmulvey](https://github.com/kmulvey)
Kyle Brandt [@kylebrandt](https://github.com/kylebrandt)
Larry Cinnabar [@larrycinnabar](https://github.com/larrycinnabar)
Leandro Piccilli [@lpic10](https://github.com/lpic10)
Lee [@leezhm](https://github.com/leezhm)
lechnertech [@lechnertech](https://github.com/lechnertech)
M. Zulfa Achsani [@misterciput](https://github.com/misterciput)
Maciej Lisiewski [@c2h5oh](https://github.com/c2h5oh)
Mara Kim [@autochthe](https://github.com/autochthe)
Marcy Buccellato [@marcybuccellato](https://github.com/marcybuccellato)
Mark Costello [@mcos](https://github.com/mcos)
Martin Häger [@protomouse](https://github.com/protomouse)
Matt Braymer-Hayes [@mattayes](https://github.com/mattayes)
Medhi Bechina [@mdzor](https://github.com/mdzor)
Mike Beshai [@mbesh](https://github.com/mbesh)
mmfrb [@mmfrb](https://github.com/mmfrb)
mnpritula [@mnpritula](https://github.com/mnpritula)
mosa [@mosasiru](https://github.com/mosasiru)
Muhammet Çakır [@cakirmuha](https://github.com/cakirmuha)
naimulhaider [@naimulhaider](https://github.com/naimulhaider)
Naoya Yoshizawa [@azihsoyn](https://github.com/azihsoyn)
navins [@ishare](https://github.com/ishare)
Naoya Tsutsumi [@tutuming](https://github.com/tutuming)
NeoCN [@NeoCN](https://github.com/NeoCN)
Nicholas Wolff [@nwolff](https://github.com/nwolff)
Nick K [@utrack](https://github.com/utrack)
Nick Whyte [@nickw444](https://github.com/nickw444)
Nicolae Vartolomei [@nvartolomei](https://github.com/nvartolomei)
okhowang [@okhowang](https://github.com/okhowang)
Orne Brocaar [@brocaar](https://github.com/brocaar)
Paul [@eyeamera](https://github.com/eyeamera)
Paul Oldenburg [@lr-paul](https://github.com/lr-paul)
Pete C [@peteclark-ft](https://github.com/peteclark-ft)
Peter Nagy [@nagypeterjob](https://github.com/nagypeterjob)
Paolo [@ppiccolo](https://github.com/ppiccolo)
Radoslaw Wesolowski [@r--w](https://github.com/r--w)
Rafał Gałus [@rgalus](https://github.com/rgalus)
rchicoli [@rchicoli](https://github.com/rchicoli)
Roman Colohanin [@zuzmic](https://github.com/zuzmic)
Ryan Schmukler [@rschmukler](https://github.com/rschmukler)
Ryan Wynn [@rwynn](https://github.com/rwynn)
Sacheendra talluri [@sacheendra](https://github.com/sacheendra)
Sean DuBois [@Sean-Der](https://github.com/Sean-Der)
Sagan Yaroslav [@sgnrslv](https://github.com/sgnrslv)
Shalin LK [@shalinlk](https://github.com/shalinlk)
singham [@zhaochenxiao90](https://github.com/zhaochenxiao90)
Slawomir CALUCH [@slawo](https://github.com/slawo)
soarpenguin [@soarpenguin](https://github.com/soarpenguin)
Stephan Krynauw [@skrynauw](https://github.com/skrynauw)
Stephen Kubovic [@stephenkubovic](https://github.com/stephenkubovic)
Stuart Warren [@Woz](https://github.com/stuart-warren)
Sulaiman [@salajlan](https://github.com/salajlan)
Sundar [@sundarv85](https://github.com/sundarv85)
Swarlston [@Swarlston](https://github.com/Swarlston)
Take [ww24](https://github.com/ww24)
Tetsuya Morimoto [@t2y](https://github.com/t2y)
TheZeroSlave [@TheZeroSlave](https://github.com/TheZeroSlave)
Tomasz Elendt [@telendt](https://github.com/telendt)
TimeEmit [@TimeEmit](https://github.com/timeemit)
TusharM [@tusharm](https://github.com/tusharm)
wangtuo [@wangtuo](https://github.com/wangtuo)
Wédney Yuri [@wedneyyuri](https://github.com/wedneyyuri)
Wesley Kim [@wesleyk](https://github.com/wesleyk)
wolfkdy [@wolfkdy](https://github.com/wolfkdy)
Wyndham Blanton [@wyndhblb](https://github.com/wyndhblb)
Yarden Bar [@ayashjorden](https://github.com/ayashjorden)
Yuya Kusakabe [@higebu](https://github.com/higebu)
zakthomas [@zakthomas](https://github.com/zakthomas)
Zach [@snowzach](https://github.com/snowzach)
zhangxin [@visaxin](https://github.com/visaxin)
@林 [@zplzpl](https://github.com/zplzpl)

View File

@@ -3,9 +3,10 @@ your issue/question without further inquiry. Thank you.
### Which version of Elastic are you using?
[ ] elastic.v2 (for Elasticsearch 1.x)
[ ] elastic.v3 (for Elasticsearch 2.x)
[ ] elastic.v6 (for Elasticsearch 6.x)
[ ] elastic.v5 (for Elasticsearch 5.x)
[ ] elastic.v3 (for Elasticsearch 2.x)
[ ] elastic.v2 (for Elasticsearch 1.x)
### Please describe the expected behavior

20
vendor/gopkg.in/olivere/elastic.v6/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright © 2012-2015 Oliver Eilhard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

View File

@@ -1,46 +1,62 @@
# Elastic
**This is a development branch that is actively being worked on. DO NOT USE IN PRODUCTION! If you want to use stable versions of Elastic, please use a dependency manager like [dep](https://github.com/golang/dep).**
Elastic is an [Elasticsearch](http://www.elasticsearch.org/) client for the
[Go](http://www.golang.org/) programming language.
[![Build Status](https://travis-ci.org/olivere/elastic.svg?branch=release-branch.v5)](https://travis-ci.org/olivere/elastic)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](http://godoc.org/gopkg.in/olivere/elastic.v5)
[![Build Status](https://travis-ci.org/olivere/elastic.svg?branch=release-branch.v6)](https://travis-ci.org/olivere/elastic)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](http://godoc.org/github.com/olivere/elastic)
[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/olivere/elastic/master/LICENSE)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Folivere%2Felastic.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Folivere%2Felastic?ref=badge_shield)
See the [wiki](https://github.com/olivere/elastic/wiki) for additional information about Elastic.
<a href="https://www.buymeacoffee.com/Bjd96U8fm" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
## Releases
**The release branches (e.g. [`release-branch.v5`](https://github.com/olivere/elastic/tree/release-branch.v5))
**The release branches (e.g. [`release-branch.v6`](https://github.com/olivere/elastic/tree/release-branch.v6))
are actively being worked on and can break at any time.
If you want to use stable versions of Elastic, please use the packages released via [gopkg.in](https://gopkg.in).**
If you want to use stable versions of Elastic, please use a dependency manager like [dep](https://github.com/golang/dep).**
Here's the version matrix:
Elasticsearch version | Elastic version -| Package URL
----------------------|------------------|------------
5.x | 5.0 | [`gopkg.in/olivere/elastic.v5`](https://gopkg.in/olivere/elastic.v5) ([source](https://github.com/olivere/elastic/tree/release-branch.v5) [doc](http://godoc.org/gopkg.in/olivere/elastic.v5))
2.x | 3.0 | [`gopkg.in/olivere/elastic.v3`](https://gopkg.in/olivere/elastic.v3) ([source](https://github.com/olivere/elastic/tree/release-branch.v3) [doc](http://godoc.org/gopkg.in/olivere/elastic.v3))
1.x | 2.0 | [`gopkg.in/olivere/elastic.v2`](https://gopkg.in/olivere/elastic.v2) ([source](https://github.com/olivere/elastic/tree/release-branch.v2) [doc](http://godoc.org/gopkg.in/olivere/elastic.v2))
0.9-1.3 | 1.0 | [`gopkg.in/olivere/elastic.v1`](https://gopkg.in/olivere/elastic.v1) ([source](https://github.com/olivere/elastic/tree/release-branch.v1) [doc](http://godoc.org/gopkg.in/olivere/elastic.v1))
Elasticsearch version | Elastic version | Package URL | Remarks |
----------------------|------------------|-------------|---------|
6.x                   | 6.0             | [`github.com/olivere/elastic`](https://github.com/olivere/elastic) ([source](https://github.com/olivere/elastic/tree/release-branch.v6) [doc](http://godoc.org/github.com/olivere/elastic)) | Use a dependency manager (see below).
5.x | 5.0 | [`gopkg.in/olivere/elastic.v5`](https://gopkg.in/olivere/elastic.v5) ([source](https://github.com/olivere/elastic/tree/release-branch.v5) [doc](http://godoc.org/gopkg.in/olivere/elastic.v5)) | Actively maintained.
2.x | 3.0 | [`gopkg.in/olivere/elastic.v3`](https://gopkg.in/olivere/elastic.v3) ([source](https://github.com/olivere/elastic/tree/release-branch.v3) [doc](http://godoc.org/gopkg.in/olivere/elastic.v3)) | Deprecated. Please update.
1.x | 2.0 | [`gopkg.in/olivere/elastic.v2`](https://gopkg.in/olivere/elastic.v2) ([source](https://github.com/olivere/elastic/tree/release-branch.v2) [doc](http://godoc.org/gopkg.in/olivere/elastic.v2)) | Deprecated. Please update.
0.9-1.3 | 1.0 | [`gopkg.in/olivere/elastic.v1`](https://gopkg.in/olivere/elastic.v1) ([source](https://github.com/olivere/elastic/tree/release-branch.v1) [doc](http://godoc.org/gopkg.in/olivere/elastic.v1)) | Deprecated. Please update.
**Example:**
You have installed Elasticsearch 5.0.0 and want to use Elastic.
As listed above, you should use Elastic 5.0.
So you first install the stable release of Elastic 5.0 from gopkg.in.
You have installed Elasticsearch 6.0.0 and want to use Elastic.
As listed above, you should use Elastic 6.0.
```sh
$ go get gopkg.in/olivere/elastic.v5
```
To use the required version of Elastic in your application, it is strongly
advised to use a tool like
[dep](https://github.com/golang/dep)
or
[Go modules](https://github.com/golang/go/wiki/Modules)
to manage dependencies. Make sure to use a version such as `^6.0.0`.
You then import it with this import path:
To use Elastic, import:
```go
import elastic "gopkg.in/olivere/elastic.v5"
import "github.com/olivere/elastic"
```
### Elastic 6.0
Elastic 6.0 targets Elasticsearch 6.x which was [released on 14th November 2017](https://www.elastic.co/blog/elasticsearch-6-0-0-released).
Notice that there are a lot of [breaking changes in Elasticsearch 6.0](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html)
and we used this as an opportunity to [clean up and refactor Elastic](https://github.com/olivere/elastic/blob/release-branch.v6/CHANGELOG-6.0.md)
as we did in the transition from earlier versions of Elastic.
### Elastic 5.0
Elastic 5.0 targets Elasticsearch 5.0.0 and later. Elasticsearch 5.0.0 was
@@ -85,8 +101,8 @@ Having said that, there have been no big API changes that required you
to rewrite your application big time. More often than not it's renaming APIs
and adding/removing features so that Elastic is in sync with Elasticsearch.
Elastic has been used in production with the following Elasticsearch versions:
0.90, 1.0-1.7, and 2.0-2.4.1. Furthermore, we use [Travis CI](https://travis-ci.org/)
Elastic has been used in production starting with Elasticsearch 0.90 up to recent 6.x
versions. Furthermore, we use [Travis CI](https://travis-ci.org/)
to test Elastic with the most recent versions of Elasticsearch and Go.
See the [.travis.yml](https://github.com/olivere/elastic/blob/master/.travis.yml)
file for the exact matrix and [Travis](https://travis-ci.org/olivere/elastic)
@@ -107,11 +123,19 @@ The client connects to Elasticsearch on `http://127.0.0.1:9200` by default.
You typically create one client for your app. Here's a complete example of
creating a client, creating an index, adding a document, executing a search etc.
An example is available [here](https://olivere.github.io/elastic/)
An example is available [here](https://olivere.github.io/elastic/).
Here's a [link to a complete working example for v3](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263).
Here's a [link to a complete working example for v6](https://gist.github.com/olivere/e4a376b4783c0914e44ea4f745ce2ebf).
See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
Here are a few tips on how to get used to Elastic:
1. Head over to the [Wiki](https://github.com/olivere/elastic/wiki) for detailed information and
topics like e.g. [how to add a middleware](https://github.com/olivere/elastic/wiki/HttpTransport)
or how to [connect to AWS](https://github.com/olivere/elastic/wiki/Using-with-AWS-Elasticsearch-Service).
2. If you are unsure how to implement something, read the tests (all `_test.go` files).
They not only serve as a guard against changes, but also as a reference.
3. The [recipes](https://github.com/olivere/elastic/tree/release-branch.v6/recipes)
contains small examples on how to implement something, e.g. bulk indexing, scrolling etc.
## API Status
@@ -143,12 +167,10 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
- [x] Context Suggester
- [x] Multi Search API
- [x] Count API
- [ ] Search Exists API
- [x] Validate API
- [x] Explain API
- [x] Profile API
- [x] Field Capabilities API
- [x] Field Stats API
### Aggregations
@@ -186,7 +208,9 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
- [x] Reverse Nested
- [x] Sampler
- [x] Significant Terms
- [x] Significant Text
- [x] Terms
- [x] Composite
- Pipeline Aggregations
- [x] Avg Bucket
- [x] Derivative
@@ -200,6 +224,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
- [x] Cumulative Sum
- [x] Bucket Script
- [x] Bucket Selector
- [x] Bucket Sort
- [x] Serial Differencing
- [x] Matrix Aggregations
- [x] Matrix Stats
@@ -222,17 +247,30 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
- [x] Update Indices Settings
- [x] Get Settings
- [x] Analyze
- [x] Explain Analyze
- [x] Index Templates
- [ ] Shadow Replica Indices
- [x] Indices Stats
- [x] Indices Segments
- [ ] Indices Recovery
- [ ] Indices Shard Stores
- [ ] Clear Cache
- [x] Flush
- [x] Synced Flush
- [x] Refresh
- [x] Force Merge
- [ ] Upgrade
### Index Lifecycle Management APIs
- [x] Create Policy
- [x] Get Policy
- [x] Delete Policy
- [ ] Move to Step
- [ ] Remove Policy
- [ ] Retry Policy
- [ ] Get Ilm Status
- [ ] Explain Lifecycle
- [ ] Start Ilm
- [ ] Stop Ilm
### cat APIs
@@ -255,6 +293,7 @@ The cat APIs are not implemented as of now. We think they are better suited for
- [ ] cat shards
- [ ] cat segments
- [ ] cat snapshots
- [ ] cat templates
### Cluster APIs
@@ -262,10 +301,12 @@ The cat APIs are not implemented as of now. We think they are better suited for
- [x] Cluster State
- [x] Cluster Stats
- [ ] Pending Cluster Tasks
- [ ] Cluster Reroute
- [x] Cluster Reroute
- [ ] Cluster Update Settings
- [x] Nodes Stats
- [x] Nodes Info
- [ ] Nodes Feature Usage
- [ ] Remote Cluster Info
- [x] Task Management API
- [ ] Nodes hot_threads
- [ ] Cluster Allocation Explain API
@@ -285,6 +326,7 @@ The cat APIs are not implemented as of now. We think they are better suited for
- Term level queries
- [x] Term Query
- [x] Terms Query
- [x] Terms Set Query
- [x] Range Query
- [x] Exists Query
- [x] Prefix Query
@@ -299,7 +341,6 @@ The cat APIs are not implemented as of now. We think they are better suited for
- [x] Dis Max Query
- [x] Function Score Query
- [x] Boosting Query
- [x] Indices Query
- Joining queries
- [x] Nested Query
- [x] Has Child Query
@@ -309,12 +350,9 @@ The cat APIs are not implemented as of now. We think they are better suited for
- [ ] GeoShape Query
- [x] Geo Bounding Box Query
- [x] Geo Distance Query
- [ ] Geo Distance Range Query
- [x] Geo Polygon Query
- [ ] Geohash Cell Query
- Specialized queries
- [x] More Like This Query
- [x] Template Query
- [x] Script Query
- [x] Percolate Query
- Span queries
@@ -334,11 +372,17 @@ The cat APIs are not implemented as of now. We think they are better suited for
- Snapshot and Restore
- [x] Repositories
- [ ] Snapshot
- [x] Snapshot get
- [x] Snapshot create
- [x] Snapshot delete
- [ ] Restore
- [ ] Snapshot status
- [ ] Monitoring snapshot/restore status
- [ ] Stopping currently running snapshot and restore
- Scripting
- [x] GetScript
- [x] PutScript
- [x] DeleteScript
### Sorting
@@ -377,3 +421,6 @@ by Joshua Tacoma,
MIT-LICENSE. See [LICENSE](http://olivere.mit-license.org/)
or the LICENSE file provided in the repository for details.
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Folivere%2Felastic.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Folivere%2Felastic?ref=badge_large)

View File

@@ -7,5 +7,7 @@ package elastic
// AcknowledgedResponse is returned from various APIs. It simply indicates
// whether the operation is ack'd or not.
type AcknowledgedResponse struct {
Acknowledged bool `json:"acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -10,8 +10,9 @@ import (
"errors"
"fmt"
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// BulkService allows for batching bulk requests and sending them to
@@ -23,7 +24,7 @@ import (
// reuse BulkService to send many batches. You do not have to create a new
// BulkService for each batch.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for more details.
type BulkService struct {
client *Client
@@ -38,6 +39,7 @@ type BulkService struct {
routing string
waitForActiveShards string
pretty bool
filterPath []string
// estimated bulk size in bytes, up to the request index sizeInBytesCursor
sizeInBytes int64
@@ -91,8 +93,11 @@ func (s *BulkService) Timeout(timeout string) *BulkService {
// Refresh controls when changes made by this request are made visible
// to search. The allowed values are: "true" (refresh the relevant
// primary and replica shards immediately), "wait_for" (wait for the
// changes to be made visible by a refresh before applying), or "false"
// (no refresh related actions).
// changes to be made visible by a refresh before reying), or "false"
// (no refresh related actions). The default value is "false".
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *BulkService) Refresh(refresh string) *BulkService {
s.refresh = refresh
return s
@@ -126,6 +131,14 @@ func (s *BulkService) Pretty(pretty bool) *BulkService {
return s
}
// FilterPath allows reducing the response, a mechanism known as
// response filtering and described here in
// https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering.
func (s *BulkService) FilterPath(filterPath ...string) *BulkService {
s.filterPath = append(s.filterPath, filterPath...)
return s
}
// Add adds bulkable requests, i.e. BulkIndexRequest, BulkUpdateRequest,
// and/or BulkDeleteRequest.
func (s *BulkService) Add(requests ...BulkableRequest) *BulkService {
@@ -227,6 +240,9 @@ func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) {
if s.pretty {
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
}
if len(s.filterPath) > 0 {
params.Set("filter_path", strings.Join(s.filterPath, ","))
}
if s.pipeline != "" {
params.Set("pipeline", s.pipeline)
}
@@ -244,7 +260,7 @@ func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) {
}
// Get response
res, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
@@ -321,10 +337,12 @@ type BulkResponseItem struct {
Type string `json:"_type,omitempty"`
Id string `json:"_id,omitempty"`
Version int64 `json:"_version,omitempty"`
Status int `json:"status,omitempty"`
Result string `json:"result,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
SeqNo int64 `json:"_seq_no,omitempty"`
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
ForcedRefresh bool `json:"forced_refresh,omitempty"`
Found bool `json:"found,omitempty"`
Error *ErrorDetails `json:"error,omitempty"`
GetResult *GetResult `json:"get,omitempty"`
}

View File

@@ -16,17 +16,19 @@ import (
// BulkDeleteRequest is a request to remove a document from Elasticsearch.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
type BulkDeleteRequest struct {
BulkableRequest
index string
typ string
id string
parent string
routing string
version int64 // default is MATCH_ANY
versionType string // default is "internal"
index string
typ string
id string
parent string
routing string
version int64 // default is MATCH_ANY
versionType string // default is "internal"
ifSeqNo *int64
ifPrimaryTerm *int64
source []string
@@ -38,13 +40,15 @@ type bulkDeleteRequestCommand map[string]bulkDeleteRequestCommandOp
//easyjson:json
type bulkDeleteRequestCommandOp struct {
Id string `json:"_id,omitempty"`
Index string `json:"_index,omitempty"`
Parent string `json:"_parent,omitempty"`
Routing string `json:"_routing,omitempty"`
Type string `json:"_type,omitempty"`
Version int64 `json:"_version,omitempty"`
VersionType string `json:"_version_type,omitempty"`
Index string `json:"_index,omitempty"`
Type string `json:"_type,omitempty"`
Id string `json:"_id,omitempty"`
Parent string `json:"parent,omitempty"`
Routing string `json:"routing,omitempty"`
Version int64 `json:"version,omitempty"`
VersionType string `json:"version_type,omitempty"`
IfSeqNo *int64 `json:"if_seq_no,omitempty"`
IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"`
}
// NewBulkDeleteRequest returns a new BulkDeleteRequest.
@@ -109,13 +113,27 @@ func (r *BulkDeleteRequest) Version(version int64) *BulkDeleteRequest {
}
// VersionType can be "internal" (default), "external", "external_gte",
// "external_gt", or "force".
// or "external_gt".
func (r *BulkDeleteRequest) VersionType(versionType string) *BulkDeleteRequest {
r.versionType = versionType
r.source = nil
return r
}
// IfSeqNo indicates to only perform the delete operation if the last
// operation that has changed the document has the specified sequence number.
func (r *BulkDeleteRequest) IfSeqNo(ifSeqNo int64) *BulkDeleteRequest {
r.ifSeqNo = &ifSeqNo
return r
}
// IfPrimaryTerm indicates to only perform the delete operation if the
// last operation that has changed the document has the specified primary term.
func (r *BulkDeleteRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkDeleteRequest {
r.ifPrimaryTerm = &ifPrimaryTerm
return r
}
// String returns the on-wire representation of the delete request,
// concatenated as a single string.
func (r *BulkDeleteRequest) String() string {
@@ -128,7 +146,7 @@ func (r *BulkDeleteRequest) String() string {
// Source returns the on-wire representation of the delete request,
// split into an action-and-meta-data line and an (optional) source line.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
func (r *BulkDeleteRequest) Source() ([]string, error) {
if r.source != nil {
@@ -136,13 +154,15 @@ func (r *BulkDeleteRequest) Source() ([]string, error) {
}
command := bulkDeleteRequestCommand{
"delete": bulkDeleteRequestCommandOp{
Index: r.index,
Type: r.typ,
Id: r.id,
Routing: r.routing,
Parent: r.parent,
Version: r.version,
VersionType: r.versionType,
Index: r.index,
Type: r.typ,
Id: r.id,
Routing: r.routing,
Parent: r.parent,
Version: r.version,
VersionType: r.versionType,
IfSeqNo: r.ifSeqNo,
IfPrimaryTerm: r.ifPrimaryTerm,
},
}

View File

@@ -17,7 +17,7 @@ var (
_ easyjson.Marshaler
)
func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDeleteRequestCommandOp) {
func easyjson8092efb6DecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkDeleteRequestCommandOp) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@@ -36,20 +36,40 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDe
continue
}
switch key {
case "_id":
out.Id = string(in.String())
case "_index":
out.Index = string(in.String())
case "_parent":
out.Parent = string(in.String())
case "_routing":
out.Routing = string(in.String())
case "_type":
out.Type = string(in.String())
case "_version":
case "_id":
out.Id = string(in.String())
case "parent":
out.Parent = string(in.String())
case "routing":
out.Routing = string(in.String())
case "version":
out.Version = int64(in.Int64())
case "_version_type":
case "version_type":
out.VersionType = string(in.String())
case "if_seq_no":
if in.IsNull() {
in.Skip()
out.IfSeqNo = nil
} else {
if out.IfSeqNo == nil {
out.IfSeqNo = new(int64)
}
*out.IfSeqNo = int64(in.Int64())
}
case "if_primary_term":
if in.IsNull() {
in.Skip()
out.IfPrimaryTerm = nil
} else {
if out.IfPrimaryTerm == nil {
out.IfPrimaryTerm = new(int64)
}
*out.IfPrimaryTerm = int64(in.Int64())
}
default:
in.SkipRecursive()
}
@@ -60,20 +80,10 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDe
in.Consumed()
}
}
func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkDeleteRequestCommandOp) {
func easyjson8092efb6EncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkDeleteRequestCommandOp) {
out.RawByte('{')
first := true
_ = first
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Id))
}
if in.Index != "" {
const prefix string = ",\"_index\":"
if first {
@@ -84,26 +94,6 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD
}
out.String(string(in.Index))
}
if in.Parent != "" {
const prefix string = ",\"_parent\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Parent))
}
if in.Routing != "" {
const prefix string = ",\"_routing\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Routing))
}
if in.Type != "" {
const prefix string = ",\"_type\":"
if first {
@@ -114,8 +104,38 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD
}
out.String(string(in.Type))
}
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Id))
}
if in.Parent != "" {
const prefix string = ",\"parent\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Parent))
}
if in.Routing != "" {
const prefix string = ",\"routing\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Routing))
}
if in.Version != 0 {
const prefix string = ",\"_version\":"
const prefix string = ",\"version\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -125,7 +145,7 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD
out.Int64(int64(in.Version))
}
if in.VersionType != "" {
const prefix string = ",\"_version_type\":"
const prefix string = ",\"version_type\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -134,33 +154,53 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD
}
out.String(string(in.VersionType))
}
if in.IfSeqNo != nil {
const prefix string = ",\"if_seq_no\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfSeqNo))
}
if in.IfPrimaryTerm != nil {
const prefix string = ",\"if_primary_term\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfPrimaryTerm))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v bulkDeleteRequestCommandOp) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson8092efb6EncodeGopkgInOlivereElasticV5(&w, v)
easyjson8092efb6EncodeGithubComOlivereElastic(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkDeleteRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) {
easyjson8092efb6EncodeGopkgInOlivereElasticV5(w, v)
easyjson8092efb6EncodeGithubComOlivereElastic(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkDeleteRequestCommandOp) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson8092efb6DecodeGopkgInOlivereElasticV5(&r, v)
easyjson8092efb6DecodeGithubComOlivereElastic(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkDeleteRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson8092efb6DecodeGopkgInOlivereElasticV5(l, v)
easyjson8092efb6DecodeGithubComOlivereElastic(l, v)
}
func easyjson8092efb6DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkDeleteRequestCommand) {
func easyjson8092efb6DecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkDeleteRequestCommand) {
isTopLevel := in.IsStart()
if in.IsNull() {
in.Skip()
@@ -185,7 +225,7 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkD
in.Consumed()
}
}
func easyjson8092efb6EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkDeleteRequestCommand) {
func easyjson8092efb6EncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkDeleteRequestCommand) {
if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 {
out.RawString(`null`)
} else {
@@ -208,23 +248,23 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk
// MarshalJSON supports json.Marshaler interface
func (v bulkDeleteRequestCommand) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson8092efb6EncodeGopkgInOlivereElasticV51(&w, v)
easyjson8092efb6EncodeGithubComOlivereElastic1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkDeleteRequestCommand) MarshalEasyJSON(w *jwriter.Writer) {
easyjson8092efb6EncodeGopkgInOlivereElasticV51(w, v)
easyjson8092efb6EncodeGithubComOlivereElastic1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkDeleteRequestCommand) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson8092efb6DecodeGopkgInOlivereElasticV51(&r, v)
easyjson8092efb6DecodeGithubComOlivereElastic1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkDeleteRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson8092efb6DecodeGopkgInOlivereElasticV51(l, v)
easyjson8092efb6DecodeGithubComOlivereElastic1(l, v)
}

View File

@@ -14,7 +14,7 @@ import (
// BulkIndexRequest is a request to add a document to Elasticsearch.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
type BulkIndexRequest struct {
BulkableRequest
@@ -24,12 +24,13 @@ type BulkIndexRequest struct {
opType string
routing string
parent string
version int64 // default is MATCH_ANY
version *int64 // default is MATCH_ANY
versionType string // default is "internal"
doc interface{}
pipeline string
retryOnConflict *int
ttl string
ifSeqNo *int64
ifPrimaryTerm *int64
source []string
@@ -41,16 +42,18 @@ type bulkIndexRequestCommand map[string]bulkIndexRequestCommandOp
//easyjson:json
type bulkIndexRequestCommandOp struct {
Id string `json:"_id,omitempty"`
Index string `json:"_index,omitempty"`
TTL string `json:"_ttl,omitempty"`
Type string `json:"_type,omitempty"`
Parent string `json:"_parent,omitempty"`
RetryOnConflict *int `json:"_retry_on_conflict,omitempty"`
Routing string `json:"_routing,omitempty"`
Version int64 `json:"_version,omitempty"`
VersionType string `json:"_version_type,omitempty"`
Index string `json:"_index,omitempty"`
Id string `json:"_id,omitempty"`
Type string `json:"_type,omitempty"`
Parent string `json:"parent,omitempty"`
// RetryOnConflict is "_retry_on_conflict" for 6.0 and "retry_on_conflict" for 6.1+.
RetryOnConflict *int `json:"retry_on_conflict,omitempty"`
Routing string `json:"routing,omitempty"`
Version *int64 `json:"version,omitempty"`
VersionType string `json:"version_type,omitempty"`
Pipeline string `json:"pipeline,omitempty"`
IfSeqNo *int64 `json:"if_seq_no,omitempty"`
IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"`
}
// NewBulkIndexRequest returns a new BulkIndexRequest.
@@ -96,7 +99,7 @@ func (r *BulkIndexRequest) Id(id string) *BulkIndexRequest {
// OpType specifies if this request should follow create-only or upsert
// behavior. This follows the OpType of the standard document index API.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#operation-type
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#operation-type
// for details.
func (r *BulkIndexRequest) OpType(opType string) *BulkIndexRequest {
r.opType = opType
@@ -121,7 +124,8 @@ func (r *BulkIndexRequest) Parent(parent string) *BulkIndexRequest {
// Version indicates the version of the document as part of an optimistic
// concurrency model.
func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest {
r.version = version
v := version
r.version = &v
r.source = nil
return r
}
@@ -129,7 +133,7 @@ func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest {
// VersionType specifies how versions are created. It can be e.g. internal,
// external, external_gte, or force.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-versioning
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#index-versioning
// for details.
func (r *BulkIndexRequest) VersionType(versionType string) *BulkIndexRequest {
r.versionType = versionType
@@ -151,13 +155,6 @@ func (r *BulkIndexRequest) RetryOnConflict(retryOnConflict int) *BulkIndexReques
return r
}
// TTL is an expiration time for the document.
func (r *BulkIndexRequest) TTL(ttl string) *BulkIndexRequest {
r.ttl = ttl
r.source = nil
return r
}
// Pipeline to use while processing the request.
func (r *BulkIndexRequest) Pipeline(pipeline string) *BulkIndexRequest {
r.pipeline = pipeline
@@ -165,6 +162,20 @@ func (r *BulkIndexRequest) Pipeline(pipeline string) *BulkIndexRequest {
return r
}
// IfSeqNo indicates to only perform the index operation if the last
// operation that has changed the document has the specified sequence number.
func (r *BulkIndexRequest) IfSeqNo(ifSeqNo int64) *BulkIndexRequest {
r.ifSeqNo = &ifSeqNo
return r
}
// IfPrimaryTerm indicates to only perform the index operation if the
// last operation that has changed the document has the specified primary term.
func (r *BulkIndexRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkIndexRequest {
r.ifPrimaryTerm = &ifPrimaryTerm
return r
}
// String returns the on-wire representation of the index request,
// concatenated as a single string.
func (r *BulkIndexRequest) String() string {
@@ -177,7 +188,7 @@ func (r *BulkIndexRequest) String() string {
// Source returns the on-wire representation of the index request,
// split into an action-and-meta-data line and an (optional) source line.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
func (r *BulkIndexRequest) Source() ([]string, error) {
// { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
@@ -199,8 +210,9 @@ func (r *BulkIndexRequest) Source() ([]string, error) {
Version: r.version,
VersionType: r.versionType,
RetryOnConflict: r.retryOnConflict,
TTL: r.ttl,
Pipeline: r.pipeline,
IfSeqNo: r.ifSeqNo,
IfPrimaryTerm: r.ifPrimaryTerm,
}
command := bulkIndexRequestCommand{
r.opType: indexCommand,

View File

@@ -17,7 +17,7 @@ var (
_ easyjson.Marshaler
)
func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIndexRequestCommandOp) {
func easyjson9de0fcbfDecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkIndexRequestCommandOp) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@@ -36,17 +36,15 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn
continue
}
switch key {
case "_id":
out.Id = string(in.String())
case "_index":
out.Index = string(in.String())
case "_ttl":
out.TTL = string(in.String())
case "_id":
out.Id = string(in.String())
case "_type":
out.Type = string(in.String())
case "_parent":
case "parent":
out.Parent = string(in.String())
case "_retry_on_conflict":
case "retry_on_conflict":
if in.IsNull() {
in.Skip()
out.RetryOnConflict = nil
@@ -56,14 +54,42 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn
}
*out.RetryOnConflict = int(in.Int())
}
case "_routing":
case "routing":
out.Routing = string(in.String())
case "_version":
out.Version = int64(in.Int64())
case "_version_type":
case "version":
if in.IsNull() {
in.Skip()
out.Version = nil
} else {
if out.Version == nil {
out.Version = new(int64)
}
*out.Version = int64(in.Int64())
}
case "version_type":
out.VersionType = string(in.String())
case "pipeline":
out.Pipeline = string(in.String())
case "if_seq_no":
if in.IsNull() {
in.Skip()
out.IfSeqNo = nil
} else {
if out.IfSeqNo == nil {
out.IfSeqNo = new(int64)
}
*out.IfSeqNo = int64(in.Int64())
}
case "if_primary_term":
if in.IsNull() {
in.Skip()
out.IfPrimaryTerm = nil
} else {
if out.IfPrimaryTerm == nil {
out.IfPrimaryTerm = new(int64)
}
*out.IfPrimaryTerm = int64(in.Int64())
}
default:
in.SkipRecursive()
}
@@ -74,20 +100,10 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn
in.Consumed()
}
}
func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkIndexRequestCommandOp) {
func easyjson9de0fcbfEncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkIndexRequestCommandOp) {
out.RawByte('{')
first := true
_ = first
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Id))
}
if in.Index != "" {
const prefix string = ",\"_index\":"
if first {
@@ -98,15 +114,15 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
}
out.String(string(in.Index))
}
if in.TTL != "" {
const prefix string = ",\"_ttl\":"
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.TTL))
out.String(string(in.Id))
}
if in.Type != "" {
const prefix string = ",\"_type\":"
@@ -119,7 +135,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
out.String(string(in.Type))
}
if in.Parent != "" {
const prefix string = ",\"_parent\":"
const prefix string = ",\"parent\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -129,7 +145,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
out.String(string(in.Parent))
}
if in.RetryOnConflict != nil {
const prefix string = ",\"_retry_on_conflict\":"
const prefix string = ",\"retry_on_conflict\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -139,7 +155,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
out.Int(int(*in.RetryOnConflict))
}
if in.Routing != "" {
const prefix string = ",\"_routing\":"
const prefix string = ",\"routing\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -148,18 +164,18 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
}
out.String(string(in.Routing))
}
if in.Version != 0 {
const prefix string = ",\"_version\":"
if in.Version != nil {
const prefix string = ",\"version\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(in.Version))
out.Int64(int64(*in.Version))
}
if in.VersionType != "" {
const prefix string = ",\"_version_type\":"
const prefix string = ",\"version_type\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -178,33 +194,53 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI
}
out.String(string(in.Pipeline))
}
if in.IfSeqNo != nil {
const prefix string = ",\"if_seq_no\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfSeqNo))
}
if in.IfPrimaryTerm != nil {
const prefix string = ",\"if_primary_term\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfPrimaryTerm))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v bulkIndexRequestCommandOp) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(&w, v)
easyjson9de0fcbfEncodeGithubComOlivereElastic(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkIndexRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) {
easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(w, v)
easyjson9de0fcbfEncodeGithubComOlivereElastic(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkIndexRequestCommandOp) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(&r, v)
easyjson9de0fcbfDecodeGithubComOlivereElastic(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkIndexRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(l, v)
easyjson9de0fcbfDecodeGithubComOlivereElastic(l, v)
}
func easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkIndexRequestCommand) {
func easyjson9de0fcbfDecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkIndexRequestCommand) {
isTopLevel := in.IsStart()
if in.IsNull() {
in.Skip()
@@ -229,7 +265,7 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkI
in.Consumed()
}
}
func easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkIndexRequestCommand) {
func easyjson9de0fcbfEncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkIndexRequestCommand) {
if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 {
out.RawString(`null`)
} else {
@@ -252,23 +288,23 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk
// MarshalJSON supports json.Marshaler interface
func (v bulkIndexRequestCommand) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(&w, v)
easyjson9de0fcbfEncodeGithubComOlivereElastic1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkIndexRequestCommand) MarshalEasyJSON(w *jwriter.Writer) {
easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(w, v)
easyjson9de0fcbfEncodeGithubComOlivereElastic1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkIndexRequestCommand) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(&r, v)
easyjson9de0fcbfDecodeGithubComOlivereElastic1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkIndexRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(l, v)
easyjson9de0fcbfDecodeGithubComOlivereElastic1(l, v)
}

View File

@@ -6,12 +6,21 @@ package elastic
import (
"context"
"errors"
"net"
"sync"
"sync/atomic"
"time"
)
var (
// ErrBulkItemRetry is returned in BulkProcessor from a worker when
// a response item needs to be retried.
ErrBulkItemRetry = errors.New("elastic: uncommitted bulk response items")
defaultRetryItemStatusCodes = []int{408, 429, 503, 507}
)
// BulkProcessorService allows to easily process bulk requests. It allows setting
// policies when to flush new bulk requests, e.g. based on a number of actions,
// on the size of the actions, and/or to flush periodically. It also allows
@@ -21,7 +30,9 @@ import (
// BulkProcessorService, by default, commits either every 1000 requests or when the
// (estimated) size of the bulk requests exceeds 5 MB. However, it does not
// commit periodically. BulkProcessorService also does retry by default, using
// an exponential backoff algorithm.
// an exponential backoff algorithm. It also will automatically re-enqueue items
// returned with a status of 408, 429, 503 or 507. You can change this
// behavior with RetryItemStatusCodes.
//
// The caller is responsible for setting the index and type on every
// bulk request added to BulkProcessorService.
@@ -30,16 +41,17 @@ import (
// Elasticsearch Java API as documented in
// https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-bulk-processor.html.
type BulkProcessorService struct {
c *Client
beforeFn BulkBeforeFunc
afterFn BulkAfterFunc
name string // name of processor
numWorkers int // # of workers (>= 1)
bulkActions int // # of requests after which to commit
bulkSize int // # of bytes after which to commit
flushInterval time.Duration // periodic flush interval
wantStats bool // indicates whether to gather statistics
backoff Backoff // a custom Backoff to use for errors
c *Client
beforeFn BulkBeforeFunc
afterFn BulkAfterFunc
name string // name of processor
numWorkers int // # of workers (>= 1)
bulkActions int // # of requests after which to commit
bulkSize int // # of bytes after which to commit
flushInterval time.Duration // periodic flush interval
wantStats bool // indicates whether to gather statistics
backoff Backoff // a custom Backoff to use for errors
retryItemStatusCodes []int // array of status codes for bulk response line items that may be retried
}
// NewBulkProcessorService creates a new BulkProcessorService.
@@ -53,6 +65,7 @@ func NewBulkProcessorService(client *Client) *BulkProcessorService {
time.Duration(200)*time.Millisecond,
time.Duration(10000)*time.Millisecond,
),
retryItemStatusCodes: defaultRetryItemStatusCodes,
}
}
@@ -64,7 +77,7 @@ type BulkBeforeFunc func(executionId int64, requests []BulkableRequest)
// after a commit to Elasticsearch. The err parameter signals an error.
type BulkAfterFunc func(executionId int64, requests []BulkableRequest, response *BulkResponse, err error)
// Before specifies a function to be executed before bulk requests get comitted
// Before specifies a function to be executed before bulk requests get committed
// to Elasticsearch.
func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService {
s.beforeFn = fn
@@ -72,7 +85,7 @@ func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService {
}
// After specifies a function to be executed when bulk requests have been
// comitted to Elasticsearch. The After callback executes both when the
// committed to Elasticsearch. The After callback executes both when the
// commit was successful as well as on failures.
func (s *BulkProcessorService) After(fn BulkAfterFunc) *BulkProcessorService {
s.afterFn = fn
@@ -122,12 +135,19 @@ func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService {
return s
}
// Backoff sets the backoff strategy to use for errors
// Backoff sets the backoff strategy to use for errors.
func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService {
s.backoff = backoff
return s
}
// RetryItemStatusCodes sets an array of status codes that indicate that a bulk
// response line item should be retried.
func (s *BulkProcessorService) RetryItemStatusCodes(retryItemStatusCodes ...int) *BulkProcessorService {
s.retryItemStatusCodes = retryItemStatusCodes
return s
}
// Do creates a new BulkProcessor and starts it.
// Consider the BulkProcessor as a running instance that accepts bulk requests
// and commits them to Elasticsearch, spreading the work across one or more
@@ -144,6 +164,12 @@ func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService {
// Calling Do several times returns new BulkProcessors. You probably don't
// want to do this. BulkProcessorService implements just a builder pattern.
func (s *BulkProcessorService) Do(ctx context.Context) (*BulkProcessor, error) {
retryItemStatusCodes := make(map[int]struct{})
for _, code := range s.retryItemStatusCodes {
retryItemStatusCodes[code] = struct{}{}
}
p := newBulkProcessor(
s.c,
s.beforeFn,
@@ -154,7 +180,8 @@ func (s *BulkProcessorService) Do(ctx context.Context) (*BulkProcessor, error) {
s.bulkSize,
s.flushInterval,
s.wantStats,
s.backoff)
s.backoff,
retryItemStatusCodes)
err := p.Start(ctx)
if err != nil {
@@ -228,21 +255,22 @@ func (st *BulkProcessorWorkerStats) dup() *BulkProcessorWorkerStats {
// BulkProcessor is returned by setting up a BulkProcessorService and
// calling the Do method.
type BulkProcessor struct {
c *Client
beforeFn BulkBeforeFunc
afterFn BulkAfterFunc
name string
bulkActions int
bulkSize int
numWorkers int
executionId int64
requestsC chan BulkableRequest
workerWg sync.WaitGroup
workers []*bulkWorker
flushInterval time.Duration
flusherStopC chan struct{}
wantStats bool
backoff Backoff
c *Client
beforeFn BulkBeforeFunc
afterFn BulkAfterFunc
name string
bulkActions int
bulkSize int
numWorkers int
executionId int64
requestsC chan BulkableRequest
workerWg sync.WaitGroup
workers []*bulkWorker
flushInterval time.Duration
flusherStopC chan struct{}
wantStats bool
retryItemStatusCodes map[int]struct{}
backoff Backoff
startedMu sync.Mutex // guards the following block
started bool
@@ -263,18 +291,20 @@ func newBulkProcessor(
bulkSize int,
flushInterval time.Duration,
wantStats bool,
backoff Backoff) *BulkProcessor {
backoff Backoff,
retryItemStatusCodes map[int]struct{}) *BulkProcessor {
return &BulkProcessor{
c: client,
beforeFn: beforeFn,
afterFn: afterFn,
name: name,
numWorkers: numWorkers,
bulkActions: bulkActions,
bulkSize: bulkSize,
flushInterval: flushInterval,
wantStats: wantStats,
backoff: backoff,
c: client,
beforeFn: beforeFn,
afterFn: afterFn,
name: name,
numWorkers: numWorkers,
bulkActions: bulkActions,
bulkSize: bulkSize,
flushInterval: flushInterval,
wantStats: wantStats,
retryItemStatusCodes: retryItemStatusCodes,
backoff: backoff,
}
}
@@ -451,9 +481,11 @@ func (w *bulkWorker) work(ctx context.Context) {
case req, open := <-w.p.requestsC:
if open {
// Received a new request
w.service.Add(req)
if w.commitRequired() {
err = w.commit(ctx)
if _, err = req.Source(); err == nil {
w.service.Add(req)
if w.commitRequired() {
err = w.commit(ctx)
}
}
} else {
// Channel closed: Stop.
@@ -462,6 +494,7 @@ func (w *bulkWorker) work(ctx context.Context) {
err = w.commit(ctx)
}
}
case <-w.flushC:
// Commit outstanding requests
if w.service.NumberOfActions() > 0 {
@@ -469,17 +502,20 @@ func (w *bulkWorker) work(ctx context.Context) {
}
w.flushAckC <- struct{}{}
}
if !stop && err != nil {
waitForActive := func() {
// Add back pressure to prevent Add calls from filling up the request queue
ready := make(chan struct{})
go w.waitForActiveConnection(ready)
<-ready
}
if _, ok := err.(net.Error); ok {
waitForActive()
} else if IsConnErr(err) {
waitForActive()
if err != nil {
w.p.c.errorf("elastic: bulk processor %q was unable to perform work: %v", w.p.name, err)
if !stop {
waitForActive := func() {
// Add back pressure to prevent Add calls from filling up the request queue
ready := make(chan struct{})
go w.waitForActiveConnection(ready)
<-ready
}
if _, ok := err.(net.Error); ok {
waitForActive()
} else if IsConnErr(err) {
waitForActive()
}
}
}
}
@@ -494,7 +530,28 @@ func (w *bulkWorker) commit(ctx context.Context) error {
// via exponential backoff
commitFunc := func() error {
var err error
// Save requests because they will be reset in service.Do
reqs := w.service.requests
res, err = w.service.Do(ctx)
if err == nil {
// Overall bulk request was OK. But each bulk response item also has a status
if w.p.retryItemStatusCodes != nil && len(w.p.retryItemStatusCodes) > 0 {
// Check res.Items since some might be soft failures
if res.Items != nil && res.Errors {
// res.Items will be 1 to 1 with reqs in same order
for i, item := range res.Items {
for _, result := range item {
if _, found := w.p.retryItemStatusCodes[result.Status]; found {
w.service.Add(reqs[i])
if err == nil {
err = ErrBulkItemRetry
}
}
}
}
}
}
}
return err
}
// notifyFunc will be called if retry fails
@@ -553,7 +610,7 @@ func (w *bulkWorker) waitForActiveConnection(ready chan<- struct{}) {
return
}
case <-t.C:
client.healthcheck(time.Duration(3)*time.Second, true)
client.healthcheck(context.Background(), 3*time.Second, true)
if client.mustActiveConn() == nil {
// found an active connection
// exit and signal done to the WaitGroup

View File

@@ -14,7 +14,7 @@ import (
// BulkUpdateRequest is a request to update a document in Elasticsearch.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
type BulkUpdateRequest struct {
BulkableRequest
@@ -34,6 +34,8 @@ type BulkUpdateRequest struct {
detectNoop *bool
doc interface{}
returnSource *bool
ifSeqNo *int64
ifPrimaryTerm *int64
source []string
@@ -45,14 +47,17 @@ type bulkUpdateRequestCommand map[string]bulkUpdateRequestCommandOp
//easyjson:json
type bulkUpdateRequestCommandOp struct {
Id string `json:"_id,omitempty"`
Index string `json:"_index,omitempty"`
Type string `json:"_type,omitempty"`
Parent string `json:"_parent,omitempty"`
RetryOnConflict *int `json:"_retry_on_conflict,omitempty"`
Routing string `json:"_routing,omitempty"`
Version int64 `json:"_version,omitempty"`
VersionType string `json:"_version_type,omitempty"`
Index string `json:"_index,omitempty"`
Type string `json:"_type,omitempty"`
Id string `json:"_id,omitempty"`
Parent string `json:"parent,omitempty"`
// RetryOnConflict is "_retry_on_conflict" for 6.0 and "retry_on_conflict" for 6.1+.
RetryOnConflict *int `json:"retry_on_conflict,omitempty"`
Routing string `json:"routing,omitempty"`
Version int64 `json:"version,omitempty"`
VersionType string `json:"version_type,omitempty"`
IfSeqNo *int64 `json:"if_seq_no,omitempty"`
IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"`
}
//easyjson:json
@@ -60,9 +65,9 @@ type bulkUpdateRequestCommandData struct {
DetectNoop *bool `json:"detect_noop,omitempty"`
Doc interface{} `json:"doc,omitempty"`
DocAsUpsert *bool `json:"doc_as_upsert,omitempty"`
Upsert interface{} `json:"upsert,omitempty"`
Script interface{} `json:"script,omitempty"`
ScriptedUpsert *bool `json:"scripted_upsert,omitempty"`
Upsert interface{} `json:"upsert,omitempty"`
Source *bool `json:"_source,omitempty"`
}
@@ -119,8 +124,8 @@ func (r *BulkUpdateRequest) Parent(parent string) *BulkUpdateRequest {
}
// Script specifies an update script.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html#bulk-update
// and https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html#bulk-update
// and https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html
// for details.
func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest {
r.script = script
@@ -131,7 +136,7 @@ func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest {
// ScripedUpsert specifies if your script will run regardless of
// whether the document exists or not.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#_literal_scripted_upsert_literal
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_literal_scripted_upsert_literal
func (r *BulkUpdateRequest) ScriptedUpsert(upsert bool) *BulkUpdateRequest {
r.scriptedUpsert = &upsert
r.source = nil
@@ -154,13 +159,27 @@ func (r *BulkUpdateRequest) Version(version int64) *BulkUpdateRequest {
}
// VersionType can be "internal" (default), "external", "external_gte",
// "external_gt", or "force".
// or "external_gt".
func (r *BulkUpdateRequest) VersionType(versionType string) *BulkUpdateRequest {
r.versionType = versionType
r.source = nil
return r
}
// IfSeqNo indicates to only perform the index operation if the last
// operation that has changed the document has the specified sequence number.
func (r *BulkUpdateRequest) IfSeqNo(ifSeqNo int64) *BulkUpdateRequest {
r.ifSeqNo = &ifSeqNo
return r
}
// IfPrimaryTerm indicates to only perform the index operation if the
// last operation that has changed the document has the specified primary term.
func (r *BulkUpdateRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkUpdateRequest {
r.ifPrimaryTerm = &ifPrimaryTerm
return r
}
// Doc specifies the updated document.
func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest {
r.doc = doc
@@ -171,7 +190,7 @@ func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest {
// DocAsUpsert indicates whether the contents of Doc should be used as
// the Upsert value.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#_literal_doc_as_upsert_literal
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_literal_doc_as_upsert_literal
// for details.
func (r *BulkUpdateRequest) DocAsUpsert(docAsUpsert bool) *BulkUpdateRequest {
r.docAsUpsert = &docAsUpsert
@@ -217,7 +236,7 @@ func (r *BulkUpdateRequest) String() string {
// Source returns the on-wire representation of the update request,
// split into an action-and-meta-data line and an (optional) source line.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html
// for details.
func (r *BulkUpdateRequest) Source() ([]string, error) {
// { "update" : { "_index" : "test", "_type" : "type1", "_id" : "1", ... } }
@@ -242,6 +261,8 @@ func (r *BulkUpdateRequest) Source() ([]string, error) {
Version: r.version,
VersionType: r.versionType,
RetryOnConflict: r.retryOnConflict,
IfSeqNo: r.ifSeqNo,
IfPrimaryTerm: r.ifPrimaryTerm,
}
command := bulkUpdateRequestCommand{
"update": updateCommand,
@@ -263,12 +284,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 {

View File

@@ -17,7 +17,7 @@ var (
_ easyjson.Marshaler
)
func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUpdateRequestCommandOp) {
func easyjson1ed00e60DecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkUpdateRequestCommandOp) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@@ -36,15 +36,15 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp
continue
}
switch key {
case "_id":
out.Id = string(in.String())
case "_index":
out.Index = string(in.String())
case "_type":
out.Type = string(in.String())
case "_parent":
case "_id":
out.Id = string(in.String())
case "parent":
out.Parent = string(in.String())
case "_retry_on_conflict":
case "retry_on_conflict":
if in.IsNull() {
in.Skip()
out.RetryOnConflict = nil
@@ -54,12 +54,32 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp
}
*out.RetryOnConflict = int(in.Int())
}
case "_routing":
case "routing":
out.Routing = string(in.String())
case "_version":
case "version":
out.Version = int64(in.Int64())
case "_version_type":
case "version_type":
out.VersionType = string(in.String())
case "if_seq_no":
if in.IsNull() {
in.Skip()
out.IfSeqNo = nil
} else {
if out.IfSeqNo == nil {
out.IfSeqNo = new(int64)
}
*out.IfSeqNo = int64(in.Int64())
}
case "if_primary_term":
if in.IsNull() {
in.Skip()
out.IfPrimaryTerm = nil
} else {
if out.IfPrimaryTerm == nil {
out.IfPrimaryTerm = new(int64)
}
*out.IfPrimaryTerm = int64(in.Int64())
}
default:
in.SkipRecursive()
}
@@ -70,20 +90,10 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp
in.Consumed()
}
}
func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkUpdateRequestCommandOp) {
func easyjson1ed00e60EncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkUpdateRequestCommandOp) {
out.RawByte('{')
first := true
_ = first
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Id))
}
if in.Index != "" {
const prefix string = ",\"_index\":"
if first {
@@ -104,8 +114,18 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
}
out.String(string(in.Type))
}
if in.Id != "" {
const prefix string = ",\"_id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Id))
}
if in.Parent != "" {
const prefix string = ",\"_parent\":"
const prefix string = ",\"parent\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -115,7 +135,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
out.String(string(in.Parent))
}
if in.RetryOnConflict != nil {
const prefix string = ",\"_retry_on_conflict\":"
const prefix string = ",\"retry_on_conflict\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -125,7 +145,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
out.Int(int(*in.RetryOnConflict))
}
if in.Routing != "" {
const prefix string = ",\"_routing\":"
const prefix string = ",\"routing\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -135,7 +155,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
out.String(string(in.Routing))
}
if in.Version != 0 {
const prefix string = ",\"_version\":"
const prefix string = ",\"version\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -145,7 +165,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
out.Int64(int64(in.Version))
}
if in.VersionType != "" {
const prefix string = ",\"_version_type\":"
const prefix string = ",\"version_type\":"
if first {
first = false
out.RawString(prefix[1:])
@@ -154,33 +174,53 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU
}
out.String(string(in.VersionType))
}
if in.IfSeqNo != nil {
const prefix string = ",\"if_seq_no\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfSeqNo))
}
if in.IfPrimaryTerm != nil {
const prefix string = ",\"if_primary_term\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int64(int64(*in.IfPrimaryTerm))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v bulkUpdateRequestCommandOp) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson1ed00e60EncodeGopkgInOlivereElasticV5(&w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkUpdateRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) {
easyjson1ed00e60EncodeGopkgInOlivereElasticV5(w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkUpdateRequestCommandOp) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson1ed00e60DecodeGopkgInOlivereElasticV5(&r, v)
easyjson1ed00e60DecodeGithubComOlivereElastic(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkUpdateRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson1ed00e60DecodeGopkgInOlivereElasticV5(l, v)
easyjson1ed00e60DecodeGithubComOlivereElastic(l, v)
}
func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkUpdateRequestCommandData) {
func easyjson1ed00e60DecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkUpdateRequestCommandData) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@@ -227,14 +267,6 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU
}
*out.DocAsUpsert = bool(in.Bool())
}
case "upsert":
if m, ok := out.Upsert.(easyjson.Unmarshaler); ok {
m.UnmarshalEasyJSON(in)
} else if m, ok := out.Upsert.(json.Unmarshaler); ok {
_ = m.UnmarshalJSON(in.Raw())
} else {
out.Upsert = in.Interface()
}
case "script":
if m, ok := out.Script.(easyjson.Unmarshaler); ok {
m.UnmarshalEasyJSON(in)
@@ -253,6 +285,14 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU
}
*out.ScriptedUpsert = bool(in.Bool())
}
case "upsert":
if m, ok := out.Upsert.(easyjson.Unmarshaler); ok {
m.UnmarshalEasyJSON(in)
} else if m, ok := out.Upsert.(json.Unmarshaler); ok {
_ = m.UnmarshalJSON(in.Raw())
} else {
out.Upsert = in.Interface()
}
case "_source":
if in.IsNull() {
in.Skip()
@@ -273,7 +313,7 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU
in.Consumed()
}
}
func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkUpdateRequestCommandData) {
func easyjson1ed00e60EncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkUpdateRequestCommandData) {
out.RawByte('{')
first := true
_ = first
@@ -313,22 +353,6 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk
}
out.Bool(bool(*in.DocAsUpsert))
}
if in.Upsert != nil {
const prefix string = ",\"upsert\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if m, ok := in.Upsert.(easyjson.Marshaler); ok {
m.MarshalEasyJSON(out)
} else if m, ok := in.Upsert.(json.Marshaler); ok {
out.Raw(m.MarshalJSON())
} else {
out.Raw(json.Marshal(in.Upsert))
}
}
if in.Script != nil {
const prefix string = ",\"script\":"
if first {
@@ -355,6 +379,22 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk
}
out.Bool(bool(*in.ScriptedUpsert))
}
if in.Upsert != nil {
const prefix string = ",\"upsert\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if m, ok := in.Upsert.(easyjson.Marshaler); ok {
m.MarshalEasyJSON(out)
} else if m, ok := in.Upsert.(json.Marshaler); ok {
out.Raw(m.MarshalJSON())
} else {
out.Raw(json.Marshal(in.Upsert))
}
}
if in.Source != nil {
const prefix string = ",\"_source\":"
if first {
@@ -371,27 +411,27 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk
// MarshalJSON supports json.Marshaler interface
func (v bulkUpdateRequestCommandData) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson1ed00e60EncodeGopkgInOlivereElasticV51(&w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkUpdateRequestCommandData) MarshalEasyJSON(w *jwriter.Writer) {
easyjson1ed00e60EncodeGopkgInOlivereElasticV51(w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkUpdateRequestCommandData) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson1ed00e60DecodeGopkgInOlivereElasticV51(&r, v)
easyjson1ed00e60DecodeGithubComOlivereElastic1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkUpdateRequestCommandData) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson1ed00e60DecodeGopkgInOlivereElasticV51(l, v)
easyjson1ed00e60DecodeGithubComOlivereElastic1(l, v)
}
func easyjson1ed00e60DecodeGopkgInOlivereElasticV52(in *jlexer.Lexer, out *bulkUpdateRequestCommand) {
func easyjson1ed00e60DecodeGithubComOlivereElastic2(in *jlexer.Lexer, out *bulkUpdateRequestCommand) {
isTopLevel := in.IsStart()
if in.IsNull() {
in.Skip()
@@ -416,7 +456,7 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV52(in *jlexer.Lexer, out *bulkU
in.Consumed()
}
}
func easyjson1ed00e60EncodeGopkgInOlivereElasticV52(out *jwriter.Writer, in bulkUpdateRequestCommand) {
func easyjson1ed00e60EncodeGithubComOlivereElastic2(out *jwriter.Writer, in bulkUpdateRequestCommand) {
if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 {
out.RawString(`null`)
} else {
@@ -439,23 +479,23 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV52(out *jwriter.Writer, in bulk
// MarshalJSON supports json.Marshaler interface
func (v bulkUpdateRequestCommand) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson1ed00e60EncodeGopkgInOlivereElasticV52(&w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic2(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v bulkUpdateRequestCommand) MarshalEasyJSON(w *jwriter.Writer) {
easyjson1ed00e60EncodeGopkgInOlivereElasticV52(w, v)
easyjson1ed00e60EncodeGithubComOlivereElastic2(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *bulkUpdateRequestCommand) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson1ed00e60DecodeGopkgInOlivereElasticV52(&r, v)
easyjson1ed00e60DecodeGithubComOlivereElastic2(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *bulkUpdateRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson1ed00e60DecodeGopkgInOlivereElasticV52(l, v)
easyjson1ed00e60DecodeGithubComOlivereElastic2(l, v)
}

169
vendor/gopkg.in/olivere/elastic.v6/cat_aliases.go generated vendored Normal file
View File

@@ -0,0 +1,169 @@
// 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"
"fmt"
"net/url"
"strings"
"github.com/olivere/elastic/uritemplates"
)
// CatAliasesService shows information about currently configured aliases
// to indices including filter and routing infos.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-aliases.html
// for details.
type CatAliasesService struct {
client *Client
pretty bool
local *bool
masterTimeout string
aliases []string
columns []string
sort []string // list of columns for sort order
}
// NewCatAliasesService creates a new CatAliasesService.
func NewCatAliasesService(client *Client) *CatAliasesService {
return &CatAliasesService{
client: client,
}
}
// Alias specifies one or more aliases to which information should be returned.
func (s *CatAliasesService) Alias(alias ...string) *CatAliasesService {
s.aliases = alias
return s
}
// Local indicates to return local information, i.e. do not retrieve
// the state from master node (default: false).
func (s *CatAliasesService) Local(local bool) *CatAliasesService {
s.local = &local
return s
}
// MasterTimeout is the explicit operation timeout for connection to master node.
func (s *CatAliasesService) MasterTimeout(masterTimeout string) *CatAliasesService {
s.masterTimeout = masterTimeout
return s
}
// Columns to return in the response.
// To get a list of all possible columns to return, run the following command
// in your terminal:
//
// Example:
// curl 'http://localhost:9200/_cat/aliases?help'
//
// You can use Columns("*") to return all possible columns. That might take
// a little longer than the default set of columns.
func (s *CatAliasesService) Columns(columns ...string) *CatAliasesService {
s.columns = columns
return s
}
// Sort is a list of fields to sort by.
func (s *CatAliasesService) Sort(fields ...string) *CatAliasesService {
s.sort = fields
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *CatAliasesService) Pretty(pretty bool) *CatAliasesService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *CatAliasesService) buildURL() (string, url.Values, error) {
// Build URL
var (
path string
err error
)
if len(s.aliases) > 0 {
path, err = uritemplates.Expand("/_cat/aliases/{name}", map[string]string{
"name": strings.Join(s.aliases, ","),
})
} else {
path = "/_cat/aliases"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{
"format": []string{"json"}, // always returns as JSON
}
if s.pretty {
params.Set("pretty", "true")
}
if v := s.local; v != nil {
params.Set("local", fmt.Sprint(*v))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if len(s.sort) > 0 {
params.Set("s", strings.Join(s.sort, ","))
}
if len(s.columns) > 0 {
params.Set("h", strings.Join(s.columns, ","))
}
return path, params, nil
}
// Do executes the operation.
func (s *CatAliasesService) Do(ctx context.Context) (CatAliasesResponse, error) {
// 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: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
var ret CatAliasesResponse
if err := s.client.decoder.Decode(res.Body, &ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a get request.
// CatAliasesResponse is the outcome of CatAliasesService.Do.
type CatAliasesResponse []CatAliasesResponseRow
// CatAliasesResponseRow is a single row in a CatAliasesResponse.
// Notice that not all of these fields might be filled; that depends
// on the number of columns chose in the request (see CatAliasesService.Columns).
type CatAliasesResponseRow struct {
// Alias name.
Alias string `json:"alias"`
// Index the alias points to.
Index string `json:"index"`
// Filter, e.g. "*" or "-".
Filter string `json:"filter"`
// RoutingIndex specifies the index routing (or "-").
RoutingIndex string `json:"routing.index"`
// RoutingSearch specifies the search routing (or "-").
RoutingSearch string `json:"routing.search"`
}

188
vendor/gopkg.in/olivere/elastic.v6/cat_allocation.go generated vendored Normal file
View File

@@ -0,0 +1,188 @@
// 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"
"fmt"
"net/url"
"strings"
"github.com/olivere/elastic/uritemplates"
)
// CatAllocationService provides a snapshot of how many shards are allocated
// to each data node and how much disk space they are using.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-allocation.html
// for details.
type CatAllocationService struct {
client *Client
pretty bool
bytes string // b, k, m, or g
local *bool
masterTimeout string
nodes []string
columns []string
sort []string // list of columns for sort order
}
// NewCatAllocationService creates a new CatAllocationService.
func NewCatAllocationService(client *Client) *CatAllocationService {
return &CatAllocationService{
client: client,
}
}
// NodeID specifies one or more node IDs to for information should be returned.
func (s *CatAllocationService) NodeID(nodes ...string) *CatAllocationService {
s.nodes = nodes
return s
}
// Bytes represents the unit in which to display byte values.
// Valid values are: "b", "k", "m", or "g".
func (s *CatAllocationService) Bytes(bytes string) *CatAllocationService {
s.bytes = bytes
return s
}
// Local indicates to return local information, i.e. do not retrieve
// the state from master node (default: false).
func (s *CatAllocationService) Local(local bool) *CatAllocationService {
s.local = &local
return s
}
// MasterTimeout is the explicit operation timeout for connection to master node.
func (s *CatAllocationService) MasterTimeout(masterTimeout string) *CatAllocationService {
s.masterTimeout = masterTimeout
return s
}
// Columns to return in the response.
// To get a list of all possible columns to return, run the following command
// in your terminal:
//
// Example:
// curl 'http://localhost:9200/_cat/aliases?help'
//
// You can use Columns("*") to return all possible columns. That might take
// a little longer than the default set of columns.
func (s *CatAllocationService) Columns(columns ...string) *CatAllocationService {
s.columns = columns
return s
}
// Sort is a list of fields to sort by.
func (s *CatAllocationService) Sort(fields ...string) *CatAllocationService {
s.sort = fields
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *CatAllocationService) Pretty(pretty bool) *CatAllocationService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *CatAllocationService) buildURL() (string, url.Values, error) {
// Build URL
var (
path string
err error
)
if len(s.nodes) > 0 {
path, err = uritemplates.Expand("/_cat/allocation/{node_id}", map[string]string{
"node_id": strings.Join(s.nodes, ","),
})
} else {
path = "/_cat/allocation"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{
"format": []string{"json"}, // always returns as JSON
}
if s.pretty {
params.Set("pretty", "true")
}
if s.bytes != "" {
params.Set("bytes", s.bytes)
}
if v := s.local; v != nil {
params.Set("local", fmt.Sprint(*v))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if len(s.sort) > 0 {
params.Set("s", strings.Join(s.sort, ","))
}
if len(s.columns) > 0 {
params.Set("h", strings.Join(s.columns, ","))
}
return path, params, nil
}
// Do executes the operation.
func (s *CatAllocationService) Do(ctx context.Context) (CatAllocationResponse, error) {
// 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: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
var ret CatAllocationResponse
if err := s.client.decoder.Decode(res.Body, &ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a get request.
// CatAllocationResponse is the outcome of CatAllocationService.Do.
type CatAllocationResponse []CatAllocationResponseRow
// CatAllocationResponseRow is a single row in a CatAllocationResponse.
// Notice that not all of these fields might be filled; that depends
// on the number of columns chose in the request (see CatAllocationService.Columns).
type CatAllocationResponseRow struct {
// Shards represents the number of shards on a node.
Shards int `json:"shards,string"`
// DiskIndices represents the disk used by ES indices, e.g. "46.1kb".
DiskIndices string `json:"disk.indices"`
// DiskUsed represents the disk used (total, not just ES), e.g. "34.5gb"
DiskUsed string `json:"disk.used"`
// DiskAvail represents the disk available, e.g. "53.2gb".
DiskAvail string `json:"disk.avail"`
// DiskTotal represents the total capacity of all volumes, e.g. "87.7gb".
DiskTotal string `json:"disk.total"`
// DiskPercent represents the percent of disk used, e.g. 39.
DiskPercent int `json:"disk.percent,string"`
// Host represents the hostname of the node.
Host string `json:"host"`
// IP represents the IP address of the node.
IP string `json:"ip"`
// Node represents the node ID.
Node string `json:"node"`
}

164
vendor/gopkg.in/olivere/elastic.v6/cat_count.go generated vendored Normal file
View File

@@ -0,0 +1,164 @@
// 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"
"fmt"
"net/url"
"strings"
"github.com/olivere/elastic/uritemplates"
)
// CatCountService provides quick access to the document count of the entire cluster,
// or individual indices.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-count.html
// for details.
type CatCountService struct {
client *Client
pretty bool
index []string
local *bool
masterTimeout string
columns []string
sort []string // list of columns for sort order
}
// NewCatCountService creates a new CatCountService.
func NewCatCountService(client *Client) *CatCountService {
return &CatCountService{
client: client,
}
}
// Index specifies zero or more indices for which to return counts
// (by default counts for all indices are returned).
func (s *CatCountService) Index(index ...string) *CatCountService {
s.index = index
return s
}
// Local indicates to return local information, i.e. do not retrieve
// the state from master node (default: false).
func (s *CatCountService) Local(local bool) *CatCountService {
s.local = &local
return s
}
// MasterTimeout is the explicit operation timeout for connection to master node.
func (s *CatCountService) MasterTimeout(masterTimeout string) *CatCountService {
s.masterTimeout = masterTimeout
return s
}
// Columns to return in the response.
// To get a list of all possible columns to return, run the following command
// in your terminal:
//
// Example:
// curl 'http://localhost:9200/_cat/count?help'
//
// You can use Columns("*") to return all possible columns. That might take
// a little longer than the default set of columns.
func (s *CatCountService) Columns(columns ...string) *CatCountService {
s.columns = columns
return s
}
// Sort is a list of fields to sort by.
func (s *CatCountService) Sort(fields ...string) *CatCountService {
s.sort = fields
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *CatCountService) Pretty(pretty bool) *CatCountService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *CatCountService) buildURL() (string, url.Values, error) {
// Build URL
var (
path string
err error
)
if len(s.index) > 0 {
path, err = uritemplates.Expand("/_cat/count/{index}", map[string]string{
"index": strings.Join(s.index, ","),
})
} else {
path = "/_cat/count"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{
"format": []string{"json"}, // always returns as JSON
}
if s.pretty {
params.Set("pretty", "true")
}
if v := s.local; v != nil {
params.Set("local", fmt.Sprint(*v))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if len(s.sort) > 0 {
params.Set("s", strings.Join(s.sort, ","))
}
if len(s.columns) > 0 {
params.Set("h", strings.Join(s.columns, ","))
}
return path, params, nil
}
// Do executes the operation.
func (s *CatCountService) Do(ctx context.Context) (CatCountResponse, error) {
// 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: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
var ret CatCountResponse
if err := s.client.decoder.Decode(res.Body, &ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a get request.
// CatCountResponse is the outcome of CatCountService.Do.
type CatCountResponse []CatCountResponseRow
// CatCountResponseRow specifies the data returned for one index
// of a CatCountResponse. Notice that not all of these fields might
// be filled; that depends on the number of columns chose in the
// request (see CatCountService.Columns).
type CatCountResponseRow struct {
Epoch int64 `json:"epoch,string"` // e.g. 1527077996
Timestamp string `json:"timestamp"` // e.g. "12:19:56"
Count int `json:"count,string"` // number of documents
}

160
vendor/gopkg.in/olivere/elastic.v6/cat_health.go generated vendored Normal file
View File

@@ -0,0 +1,160 @@
// 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"
"fmt"
"net/url"
"strings"
)
// CatHealthService returns a terse representation of the same information
// as /_cluster/health.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-health.html
// for details.
type CatHealthService struct {
client *Client
pretty bool
local *bool
masterTimeout string
columns []string
sort []string // list of columns for sort order
disableTimestamping *bool
}
// NewCatHealthService creates a new CatHealthService.
func NewCatHealthService(client *Client) *CatHealthService {
return &CatHealthService{
client: client,
}
}
// Local indicates to return local information, i.e. do not retrieve
// the state from master node (default: false).
func (s *CatHealthService) Local(local bool) *CatHealthService {
s.local = &local
return s
}
// MasterTimeout is the explicit operation timeout for connection to master node.
func (s *CatHealthService) MasterTimeout(masterTimeout string) *CatHealthService {
s.masterTimeout = masterTimeout
return s
}
// Columns to return in the response.
// To get a list of all possible columns to return, run the following command
// in your terminal:
//
// Example:
// curl 'http://localhost:9200/_cat/indices?help'
//
// You can use Columns("*") to return all possible columns. That might take
// a little longer than the default set of columns.
func (s *CatHealthService) Columns(columns ...string) *CatHealthService {
s.columns = columns
return s
}
// Sort is a list of fields to sort by.
func (s *CatHealthService) Sort(fields ...string) *CatHealthService {
s.sort = fields
return s
}
// DisableTimestamping disables timestamping (default: true).
func (s *CatHealthService) DisableTimestamping(disable bool) *CatHealthService {
s.disableTimestamping = &disable
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *CatHealthService) Pretty(pretty bool) *CatHealthService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *CatHealthService) buildURL() (string, url.Values, error) {
// Build URL
path := "/_cat/health"
// Add query string parameters
params := url.Values{
"format": []string{"json"}, // always returns as JSON
}
if s.pretty {
params.Set("pretty", "true")
}
if v := s.local; v != nil {
params.Set("local", fmt.Sprint(*v))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if len(s.sort) > 0 {
params.Set("s", strings.Join(s.sort, ","))
}
if v := s.disableTimestamping; v != nil {
params.Set("ts", fmt.Sprint(*v))
}
if len(s.columns) > 0 {
params.Set("h", strings.Join(s.columns, ","))
}
return path, params, nil
}
// Do executes the operation.
func (s *CatHealthService) Do(ctx context.Context) (CatHealthResponse, error) {
// 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: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
var ret CatHealthResponse
if err := s.client.decoder.Decode(res.Body, &ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a get request.
// CatHealthResponse is the outcome of CatHealthService.Do.
type CatHealthResponse []CatHealthResponseRow
// CatHealthResponseRow is a single row in a CatHealthResponse.
// Notice that not all of these fields might be filled; that depends
// on the number of columns chose in the request (see CatHealthService.Columns).
type CatHealthResponseRow struct {
Epoch int64 `json:"epoch,string"` // e.g. 1527077996
Timestamp string `json:"timestamp"` // e.g. "12:19:56"
Cluster string `json:"cluster"` // cluster name, e.g. "elasticsearch"
Status string `json:"status"` // health status, e.g. "green", "yellow", or "red"
NodeTotal int `json:"node.total,string"` // total number of nodes
NodeData int `json:"node.data,string"` // number of nodes that can store data
Shards int `json:"shards,string"` // total number of shards
Pri int `json:"pri,string"` // number of primary shards
Relo int `json:"relo,string"` // number of relocating nodes
Init int `json:"init,string"` // number of initializing nodes
Unassign int `json:"unassign,string"` // number of unassigned shards
PendingTasks int `json:"pending_tasks,string"` // number of pending tasks
MaxTaskWaitTime string `json:"max_task_wait_time"` // wait time of longest task pending, e.g. "-" or time in millis
ActiveShardsPercent string `json:"active_shards_percent"` // active number of shards in percent, e.g. "100%"
}

318
vendor/gopkg.in/olivere/elastic.v6/cat_indices.go generated vendored Normal file
View File

@@ -0,0 +1,318 @@
// 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"
"fmt"
"net/url"
"strings"
"github.com/olivere/elastic/uritemplates"
)
// CatIndicesService returns the list of indices plus some additional
// information about them.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-indices.html
// for details.
type CatIndicesService struct {
client *Client
pretty bool
index string
bytes string // b, k, m, or g
local *bool
masterTimeout string
columns []string
health string // green, yellow, or red
primaryOnly *bool // true for primary shards only
sort []string // list of columns for sort order
}
// NewCatIndicesService creates a new CatIndicesService.
func NewCatIndicesService(client *Client) *CatIndicesService {
return &CatIndicesService{
client: client,
}
}
// Index is the name of the index to list (by default all indices are returned).
func (s *CatIndicesService) Index(index string) *CatIndicesService {
s.index = index
return s
}
// Bytes represents the unit in which to display byte values.
// Valid values are: "b", "k", "m", or "g".
func (s *CatIndicesService) Bytes(bytes string) *CatIndicesService {
s.bytes = bytes
return s
}
// Local indicates to return local information, i.e. do not retrieve
// the state from master node (default: false).
func (s *CatIndicesService) Local(local bool) *CatIndicesService {
s.local = &local
return s
}
// MasterTimeout is the explicit operation timeout for connection to master node.
func (s *CatIndicesService) MasterTimeout(masterTimeout string) *CatIndicesService {
s.masterTimeout = masterTimeout
return s
}
// Columns to return in the response.
// To get a list of all possible columns to return, run the following command
// in your terminal:
//
// Example:
// curl 'http://localhost:9200/_cat/indices?help'
//
// You can use Columns("*") to return all possible columns. That might take
// a little longer than the default set of columns.
func (s *CatIndicesService) Columns(columns ...string) *CatIndicesService {
s.columns = columns
return s
}
// Health filters indices by their health status.
// Valid values are: "green", "yellow", or "red".
func (s *CatIndicesService) Health(healthState string) *CatIndicesService {
s.health = healthState
return s
}
// PrimaryOnly when set to true returns stats only for primary shards (default: false).
func (s *CatIndicesService) PrimaryOnly(primaryOnly bool) *CatIndicesService {
s.primaryOnly = &primaryOnly
return s
}
// Sort is a list of fields to sort by.
func (s *CatIndicesService) Sort(fields ...string) *CatIndicesService {
s.sort = fields
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *CatIndicesService) Pretty(pretty bool) *CatIndicesService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *CatIndicesService) buildURL() (string, url.Values, error) {
// Build URL
var (
path string
err error
)
if s.index != "" {
path, err = uritemplates.Expand("/_cat/indices/{index}", map[string]string{
"index": s.index,
})
} else {
path = "/_cat/indices"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{
"format": []string{"json"}, // always returns as JSON
}
if s.pretty {
params.Set("pretty", "true")
}
if s.bytes != "" {
params.Set("bytes", s.bytes)
}
if v := s.local; v != nil {
params.Set("local", fmt.Sprint(*v))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if len(s.columns) > 0 {
params.Set("h", strings.Join(s.columns, ","))
}
if s.health != "" {
params.Set("health", s.health)
}
if v := s.primaryOnly; v != nil {
params.Set("pri", fmt.Sprint(*v))
}
if len(s.sort) > 0 {
params.Set("s", strings.Join(s.sort, ","))
}
return path, params, nil
}
// Do executes the operation.
func (s *CatIndicesService) Do(ctx context.Context) (CatIndicesResponse, error) {
// 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: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
var ret CatIndicesResponse
if err := s.client.decoder.Decode(res.Body, &ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a get request.
// CatIndicesResponse is the outcome of CatIndicesService.Do.
type CatIndicesResponse []CatIndicesResponseRow
// CatIndicesResponseRow specifies the data returned for one index
// of a CatIndicesResponse. Notice that not all of these fields might
// be filled; that depends on the number of columns chose in the
// request (see CatIndicesService.Columns).
type CatIndicesResponseRow struct {
Health string `json:"health"` // "green", "yellow", or "red"
Status string `json:"status"` // "open" or "closed"
Index string `json:"index"` // index name
UUID string `json:"uuid"` // index uuid
Pri int `json:"pri,string"` // number of primary shards
Rep int `json:"rep,string"` // number of replica shards
DocsCount int `json:"docs.count,string"` // number of available documents
DocsDeleted int `json:"docs.deleted,string"` // number of deleted documents
CreationDate int64 `json:"creation.date,string"` // index creation date (millisecond value), e.g. 1527077221644
CreationDateString string `json:"creation.date.string"` // index creation date (as string), e.g. "2018-05-23T12:07:01.644Z"
StoreSize string `json:"store.size"` // store size of primaries & replicas, e.g. "4.6kb"
PriStoreSize string `json:"pri.store.size"` // store size of primaries, e.g. "230b"
CompletionSize string `json:"completion.size"` // size of completion on primaries & replicas
PriCompletionSize string `json:"pri.completion.size"` // size of completion on primaries
FielddataMemorySize string `json:"fielddata.memory_size"` // used fielddata cache on primaries & replicas
PriFielddataMemorySize string `json:"pri.fielddata.memory_size"` // used fielddata cache on primaries
FielddataEvictions int `json:"fielddata.evictions,string"` // fielddata evictions on primaries & replicas
PriFielddataEvictions int `json:"pri.fielddata.evictions,string"` // fielddata evictions on primaries
QueryCacheMemorySize string `json:"query_cache.memory_size"` // used query cache on primaries & replicas
PriQueryCacheMemorySize string `json:"pri.query_cache.memory_size"` // used query cache on primaries
QueryCacheEvictions int `json:"query_cache.evictions,string"` // query cache evictions on primaries & replicas
PriQueryCacheEvictions int `json:"pri.query_cache.evictions,string"` // query cache evictions on primaries
RequestCacheMemorySize string `json:"request_cache.memory_size"` // used request cache on primaries & replicas
PriRequestCacheMemorySize string `json:"pri.request_cache.memory_size"` // used request cache on primaries
RequestCacheEvictions int `json:"request_cache.evictions,string"` // request cache evictions on primaries & replicas
PriRequestCacheEvictions int `json:"pri.request_cache.evictions,string"` // request cache evictions on primaries
RequestCacheHitCount int `json:"request_cache.hit_count,string"` // request cache hit count on primaries & replicas
PriRequestCacheHitCount int `json:"pri.request_cache.hit_count,string"` // request cache hit count on primaries
RequestCacheMissCount int `json:"request_cache.miss_count,string"` // request cache miss count on primaries & replicas
PriRequestCacheMissCount int `json:"pri.request_cache.miss_count,string"` // request cache miss count on primaries
FlushTotal int `json:"flush.total"` // number of flushes on primaries & replicas
PriFlushTotal int `json:"pri.flush.total"` // number of flushes on primaries
FlushTotalTime string `json:"flush.total_time"` // time spent in flush on primaries & replicas
PriFlushTotalTime string `json:"pri.flush.total_time"` // time spent in flush on primaries
GetCurrent int `json:"get.current,string"` // number of current get ops on primaries & replicas
PriGetCurrent int `json:"pri.get.current,string"` // number of current get ops on primaries
GetTime string `json:"get.time"` // time spent in get on primaries & replicas
PriGetTime string `json:"pri.get.time"` // time spent in get on primaries
GetTotal int `json:"get.total,string"` // number of get ops on primaries & replicas
PriGetTotal int `json:"pri.get.total,string"` // number of get ops on primaries
GetExistsTime string `json:"get.exists_time"` // time spent in successful gets on primaries & replicas
PriGetExistsTime string `json:"pri.get.exists_time"` // time spent in successful gets on primaries
GetExistsTotal int `json:"get.exists_total,string"` // number of successful gets on primaries & replicas
PriGetExistsTotal int `json:"pri.get.exists_total,string"` // number of successful gets on primaries
GetMissingTime string `json:"get.missing_time"` // time spent in failed gets on primaries & replicas
PriGetMissingTime string `json:"pri.get.missing_time"` // time spent in failed gets on primaries
GetMissingTotal int `json:"get.missing_total,string"` // number of failed gets on primaries & replicas
PriGetMissingTotal int `json:"pri.get.missing_total,string"` // number of failed gets on primaries
IndexingDeleteCurrent int `json:"indexing.delete_current,string"` // number of current deletions on primaries & replicas
PriIndexingDeleteCurrent int `json:"pri.indexing.delete_current,string"` // number of current deletions on primaries
IndexingDeleteTime string `json:"indexing.delete_time"` // time spent in deletions on primaries & replicas
PriIndexingDeleteTime string `json:"pri.indexing.delete_time"` // time spent in deletions on primaries
IndexingDeleteTotal int `json:"indexing.delete_total,string"` // number of delete ops on primaries & replicas
PriIndexingDeleteTotal int `json:"pri.indexing.delete_total,string"` // number of delete ops on primaries
IndexingIndexCurrent int `json:"indexing.index_current,string"` // number of current indexing on primaries & replicas
PriIndexingIndexCurrent int `json:"pri.indexing.index_current,string"` // number of current indexing on primaries
IndexingIndexTime string `json:"indexing.index_time"` // time spent in indexing on primaries & replicas
PriIndexingIndexTime string `json:"pri.indexing.index_time"` // time spent in indexing on primaries
IndexingIndexTotal int `json:"indexing.index_total,string"` // number of index ops on primaries & replicas
PriIndexingIndexTotal int `json:"pri.indexing.index_total,string"` // number of index ops on primaries
IndexingIndexFailed int `json:"indexing.index_failed,string"` // number of failed indexing ops on primaries & replicas
PriIndexingIndexFailed int `json:"pri.indexing.index_failed,string"` // number of failed indexing ops on primaries
MergesCurrent int `json:"merges.current,string"` // number of current merges on primaries & replicas
PriMergesCurrent int `json:"pri.merges.current,string"` // number of current merges on primaries
MergesCurrentDocs int `json:"merges.current_docs,string"` // number of current merging docs on primaries & replicas
PriMergesCurrentDocs int `json:"pri.merges.current_docs,string"` // number of current merging docs on primaries
MergesCurrentSize string `json:"merges.current_size"` // size of current merges on primaries & replicas
PriMergesCurrentSize string `json:"pri.merges.current_size"` // size of current merges on primaries
MergesTotal int `json:"merges.total,string"` // number of completed merge ops on primaries & replicas
PriMergesTotal int `json:"pri.merges.total,string"` // number of completed merge ops on primaries
MergesTotalDocs int `json:"merges.total_docs,string"` // docs merged on primaries & replicas
PriMergesTotalDocs int `json:"pri.merges.total_docs,string"` // docs merged on primaries
MergesTotalSize string `json:"merges.total_size"` // size merged on primaries & replicas
PriMergesTotalSize string `json:"pri.merges.total_size"` // size merged on primaries
MergesTotalTime string `json:"merges.total_time"` // time spent in merges on primaries & replicas
PriMergesTotalTime string `json:"pri.merges.total_time"` // time spent in merges on primaries
RefreshTotal int `json:"refresh.total,string"` // total refreshes on primaries & replicas
PriRefreshTotal int `json:"pri.refresh.total,string"` // total refreshes on primaries
RefreshTime string `json:"refresh.time"` // time spent in refreshes on primaries & replicas
PriRefreshTime string `json:"pri.refresh.time"` // time spent in refreshes on primaries
RefreshListeners int `json:"refresh.listeners,string"` // number of pending refresh listeners on primaries & replicas
PriRefreshListeners int `json:"pri.refresh.listeners,string"` // number of pending refresh listeners on primaries
SearchFetchCurrent int `json:"search.fetch_current,string"` // current fetch phase ops on primaries & replicas
PriSearchFetchCurrent int `json:"pri.search.fetch_current,string"` // current fetch phase ops on primaries
SearchFetchTime string `json:"search.fetch_time"` // time spent in fetch phase on primaries & replicas
PriSearchFetchTime string `json:"pri.search.fetch_time"` // time spent in fetch phase on primaries
SearchFetchTotal int `json:"search.fetch_total,string"` // total fetch ops on primaries & replicas
PriSearchFetchTotal int `json:"pri.search.fetch_total,string"` // total fetch ops on primaries
SearchOpenContexts int `json:"search.open_contexts,string"` // open search contexts on primaries & replicas
PriSearchOpenContexts int `json:"pri.search.open_contexts,string"` // open search contexts on primaries
SearchQueryCurrent int `json:"search.query_current,string"` // current query phase ops on primaries & replicas
PriSearchQueryCurrent int `json:"pri.search.query_current,string"` // current query phase ops on primaries
SearchQueryTime string `json:"search.query_time"` // time spent in query phase on primaries & replicas, e.g. "0s"
PriSearchQueryTime string `json:"pri.search.query_time"` // time spent in query phase on primaries, e.g. "0s"
SearchQueryTotal int `json:"search.query_total,string"` // total query phase ops on primaries & replicas
PriSearchQueryTotal int `json:"pri.search.query_total,string"` // total query phase ops on primaries
SearchScrollCurrent int `json:"search.scroll_current,string"` // open scroll contexts on primaries & replicas
PriSearchScrollCurrent int `json:"pri.search.scroll_current,string"` // open scroll contexts on primaries
SearchScrollTime string `json:"search.scroll_time"` // time scroll contexts held open on primaries & replicas, e.g. "0s"
PriSearchScrollTime string `json:"pri.search.scroll_time"` // time scroll contexts held open on primaries, e.g. "0s"
SearchScrollTotal int `json:"search.scroll_total,string"` // completed scroll contexts on primaries & replicas
PriSearchScrollTotal int `json:"pri.search.scroll_total,string"` // completed scroll contexts on primaries
SegmentsCount int `json:"segments.count,string"` // number of segments on primaries & replicas
PriSegmentsCount int `json:"pri.segments.count,string"` // number of segments on primaries
SegmentsMemory string `json:"segments.memory"` // memory used by segments on primaries & replicas, e.g. "1.3kb"
PriSegmentsMemory string `json:"pri.segments.memory"` // memory used by segments on primaries, e.g. "1.3kb"
SegmentsIndexWriterMemory string `json:"segments.index_writer_memory"` // memory used by index writer on primaries & replicas, e.g. "0b"
PriSegmentsIndexWriterMemory string `json:"pri.segments.index_writer_memory"` // memory used by index writer on primaries, e.g. "0b"
SegmentsVersionMapMemory string `json:"segments.version_map_memory"` // memory used by version map on primaries & replicas, e.g. "0b"
PriSegmentsVersionMapMemory string `json:"pri.segments.version_map_memory"` // memory used by version map on primaries, e.g. "0b"
SegmentsFixedBitsetMemory string `json:"segments.fixed_bitset_memory"` // memory used by fixed bit sets for nested object field types and type filters for types referred in _parent fields on primaries & replicas, e.g. "0b"
PriSegmentsFixedBitsetMemory string `json:"pri.segments.fixed_bitset_memory"` // memory used by fixed bit sets for nested object field types and type filters for types referred in _parent fields on primaries, e.g. "0b"
WarmerCurrent int `json:"warmer.count,string"` // current warmer ops on primaries & replicas
PriWarmerCurrent int `json:"pri.warmer.count,string"` // current warmer ops on primaries
WarmerTotal int `json:"warmer.total,string"` // total warmer ops on primaries & replicas
PriWarmerTotal int `json:"pri.warmer.total,string"` // total warmer ops on primaries
WarmerTotalTime string `json:"warmer.total_time"` // time spent in warmers on primaries & replicas, e.g. "47s"
PriWarmerTotalTime string `json:"pri.warmer.total_time"` // time spent in warmers on primaries, e.g. "47s"
SuggestCurrent int `json:"suggest.current,string"` // number of current suggest ops on primaries & replicas
PriSuggestCurrent int `json:"pri.suggest.current,string"` // number of current suggest ops on primaries
SuggestTime string `json:"suggest.time"` // time spend in suggest on primaries & replicas, "31s"
PriSuggestTime string `json:"pri.suggest.time"` // time spend in suggest on primaries, e.g. "31s"
SuggestTotal int `json:"suggest.total,string"` // number of suggest ops on primaries & replicas
PriSuggestTotal int `json:"pri.suggest.total,string"` // number of suggest ops on primaries
MemoryTotal string `json:"memory.total"` // total user memory on primaries & replicas, e.g. "1.5kb"
PriMemoryTotal string `json:"pri.memory.total"` // total user memory on primaries, e.g. "1.5kb"
}

View File

@@ -12,7 +12,7 @@ import (
// ClearScrollService clears one or more scroll contexts by their ids.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#_clear_scroll_api
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html#_clear_scroll_api
// for details.
type ClearScrollService struct {
client *Client
@@ -49,7 +49,7 @@ func (s *ClearScrollService) 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
}
@@ -85,7 +85,12 @@ func (s *ClearScrollService) Do(ctx context.Context) (*ClearScrollResponse, erro
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "DELETE", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "DELETE",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}

View File

@@ -21,12 +21,12 @@ import (
"github.com/pkg/errors"
"gopkg.in/olivere/elastic.v5/config"
"github.com/olivere/elastic/config"
)
const (
// Version is the current version of Elastic.
Version = "5.0.82"
Version = "6.2.23"
// 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.
@@ -134,8 +134,8 @@ type Client struct {
basicAuthUsername string // username for HTTP Basic Auth
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)
requiredPlugins []string // list of required plugins
retrier Retrier // strategy for retries
}
@@ -158,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/5.2/cluster-nodes-info.html#cluster-nodes-info).
// (see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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.
@@ -190,147 +190,16 @@ type Client struct {
// An error is also returned when some configuration option is invalid or
// the new client cannot sniff the cluster (if enabled).
func NewClient(options ...ClientOptionFunc) (*Client, error) {
// Set up the client
c := &Client{
c: http.DefaultClient,
conns: make([]*conn, 0),
cindex: -1,
scheme: DefaultScheme,
decoder: &DefaultDecoder{},
healthcheckEnabled: DefaultHealthcheckEnabled,
healthcheckTimeoutStartup: DefaultHealthcheckTimeoutStartup,
healthcheckTimeout: DefaultHealthcheckTimeout,
healthcheckInterval: DefaultHealthcheckInterval,
healthcheckStop: make(chan bool),
snifferEnabled: DefaultSnifferEnabled,
snifferTimeoutStartup: DefaultSnifferTimeoutStartup,
snifferTimeout: DefaultSnifferTimeout,
snifferInterval: DefaultSnifferInterval,
snifferCallback: nopSnifferCallback,
snifferStop: make(chan bool),
sendGetBodyAs: DefaultSendGetBodyAs,
gzipEnabled: DefaultGzipEnabled,
retrier: noRetries, // no retries by default
}
// Run the options on it
for _, option := range options {
if err := option(c); err != nil {
return nil, err
}
}
// Use a default URL and normalize them
if len(c.urls) == 0 {
c.urls = []string{DefaultURL}
}
c.urls = canonicalize(c.urls...)
// If the URLs have auth info, use them here as an alternative to SetBasicAuth
if !c.basicAuth {
for _, urlStr := range c.urls {
u, err := url.Parse(urlStr)
if err == nil && u.User != nil {
c.basicAuth = true
c.basicAuthUsername = u.User.Username()
c.basicAuthPassword, _ = u.User.Password()
break
}
}
}
// Check if we can make a request to any of the specified URLs
if c.healthcheckEnabled {
if err := c.startupHealthcheck(c.healthcheckTimeoutStartup); err != nil {
return nil, err
}
}
if c.snifferEnabled {
// Sniff the cluster initially
if err := c.sniff(c.snifferTimeoutStartup); err != nil {
return nil, err
}
} else {
// Do not sniff the cluster initially. Use the provided URLs instead.
for _, url := range c.urls {
c.conns = append(c.conns, newConn(url, url))
}
}
if c.healthcheckEnabled {
// Perform an initial health check
c.healthcheck(c.healthcheckTimeoutStartup, true)
}
// Ensure that we have at least one connection available
if err := c.mustActiveConn(); err != nil {
return nil, err
}
// Check the required plugins
for _, plugin := range c.requiredPlugins {
found, err := c.HasPlugin(plugin)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("elastic: plugin %s not found", plugin)
}
}
if c.snifferEnabled {
go c.sniffer() // periodically update cluster information
}
if c.healthcheckEnabled {
go c.healthchecker() // start goroutine periodically ping all nodes of the cluster
}
c.mu.Lock()
c.running = true
c.mu.Unlock()
return c, nil
return DialContext(context.Background(), options...)
}
// NewClientFromConfig initializes a client from a configuration.
func NewClientFromConfig(cfg *config.Config) (*Client, error) {
var options []ClientOptionFunc
if cfg != nil {
if cfg.URL != "" {
options = append(options, SetURL(cfg.URL))
}
if cfg.Errorlog != "" {
f, err := os.OpenFile(cfg.Errorlog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize error log")
}
l := log.New(f, "", 0)
options = append(options, SetErrorLog(l))
}
if cfg.Tracelog != "" {
f, err := os.OpenFile(cfg.Tracelog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize trace log")
}
l := log.New(f, "", 0)
options = append(options, SetTraceLog(l))
}
if cfg.Infolog != "" {
f, err := os.OpenFile(cfg.Infolog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize info log")
}
l := log.New(f, "", 0)
options = append(options, SetInfoLog(l))
}
if cfg.Username != "" || cfg.Password != "" {
options = append(options, SetBasicAuth(cfg.Username, cfg.Password))
}
if cfg.Sniff != nil {
options = append(options, SetSniff(*cfg.Sniff))
}
options, err := configToOptions(cfg)
if err != nil {
return nil, err
}
return NewClient(options...)
return DialContext(context.Background(), options...)
}
// NewSimpleClient creates a new short-lived Client that can be used in
@@ -424,6 +293,174 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) {
return c, nil
}
// Dial will call DialContext with a background context.
func Dial(options ...ClientOptionFunc) (*Client, error) {
return DialContext(context.Background(), options...)
}
// DialContext will connect to Elasticsearch, just like NewClient does.
//
// The context is honoured in terms of e.g. cancellation.
func DialContext(ctx context.Context, options ...ClientOptionFunc) (*Client, error) {
// Set up the client
c := &Client{
c: http.DefaultClient,
conns: make([]*conn, 0),
cindex: -1,
scheme: DefaultScheme,
decoder: &DefaultDecoder{},
healthcheckEnabled: DefaultHealthcheckEnabled,
healthcheckTimeoutStartup: DefaultHealthcheckTimeoutStartup,
healthcheckTimeout: DefaultHealthcheckTimeout,
healthcheckInterval: DefaultHealthcheckInterval,
healthcheckStop: make(chan bool),
snifferEnabled: DefaultSnifferEnabled,
snifferTimeoutStartup: DefaultSnifferTimeoutStartup,
snifferTimeout: DefaultSnifferTimeout,
snifferInterval: DefaultSnifferInterval,
snifferCallback: nopSnifferCallback,
snifferStop: make(chan bool),
sendGetBodyAs: DefaultSendGetBodyAs,
gzipEnabled: DefaultGzipEnabled,
retrier: noRetries, // no retries by default
}
// Run the options on it
for _, option := range options {
if err := option(c); err != nil {
return nil, err
}
}
// Use a default URL and normalize them
if len(c.urls) == 0 {
c.urls = []string{DefaultURL}
}
c.urls = canonicalize(c.urls...)
// If the URLs have auth info, use them here as an alternative to SetBasicAuth
if !c.basicAuth {
for _, urlStr := range c.urls {
u, err := url.Parse(urlStr)
if err == nil && u.User != nil {
c.basicAuth = true
c.basicAuthUsername = u.User.Username()
c.basicAuthPassword, _ = u.User.Password()
break
}
}
}
// Check if we can make a request to any of the specified URLs
if c.healthcheckEnabled {
if err := c.startupHealthcheck(ctx, c.healthcheckTimeoutStartup); err != nil {
return nil, err
}
}
if c.snifferEnabled {
// Sniff the cluster initially
if err := c.sniff(ctx, c.snifferTimeoutStartup); err != nil {
return nil, err
}
} else {
// Do not sniff the cluster initially. Use the provided URLs instead.
for _, url := range c.urls {
c.conns = append(c.conns, newConn(url, url))
}
}
if c.healthcheckEnabled {
// Perform an initial health check
c.healthcheck(ctx, c.healthcheckTimeoutStartup, true)
}
// Ensure that we have at least one connection available
if err := c.mustActiveConn(); err != nil {
return nil, err
}
// Check the required plugins
for _, plugin := range c.requiredPlugins {
found, err := c.HasPlugin(plugin)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("elastic: plugin %s not found", plugin)
}
}
if c.snifferEnabled {
go c.sniffer() // periodically update cluster information
}
if c.healthcheckEnabled {
go c.healthchecker() // start goroutine periodically ping all nodes of the cluster
}
c.mu.Lock()
c.running = true
c.mu.Unlock()
return c, nil
}
// DialWithConfig will use the configuration settings parsed from config package
// to connect to Elasticsearch.
//
// The context is honoured in terms of e.g. cancellation.
func DialWithConfig(ctx context.Context, cfg *config.Config) (*Client, error) {
options, err := configToOptions(cfg)
if err != nil {
return nil, err
}
return DialContext(ctx, options...)
}
func configToOptions(cfg *config.Config) ([]ClientOptionFunc, error) {
var options []ClientOptionFunc
if cfg != nil {
if cfg.URL != "" {
options = append(options, SetURL(cfg.URL))
}
if cfg.Errorlog != "" {
f, err := os.OpenFile(cfg.Errorlog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize error log")
}
l := log.New(f, "", 0)
options = append(options, SetErrorLog(l))
}
if cfg.Tracelog != "" {
f, err := os.OpenFile(cfg.Tracelog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize trace log")
}
l := log.New(f, "", 0)
options = append(options, SetTraceLog(l))
}
if cfg.Infolog != "" {
f, err := os.OpenFile(cfg.Infolog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "unable to initialize info log")
}
l := log.New(f, "", 0)
options = append(options, SetInfoLog(l))
}
if cfg.Username != "" || cfg.Password != "" {
options = append(options, SetBasicAuth(cfg.Username, cfg.Password))
}
if cfg.Sniff != nil {
options = append(options, SetSniff(*cfg.Sniff))
}
/*
if cfg.Healthcheck != nil {
options = append(options, SetHealthcheck(*cfg.Healthcheck))
}
*/
}
return options, nil
}
// SetHttpClient can be used to specify the http.Client to use when making
// HTTP requests to Elasticsearch.
func SetHttpClient(httpClient *http.Client) ClientOptionFunc {
@@ -816,7 +853,7 @@ func (c *Client) sniffer() {
c.snifferStop <- true
return
case <-ticker.C:
c.sniff(timeout)
c.sniff(context.Background(), timeout)
}
}
}
@@ -826,7 +863,7 @@ func (c *Client) sniffer() {
// by the preceding sniffing process (if sniffing is enabled).
//
// If sniffing is disabled, this is a no-op.
func (c *Client) sniff(timeout time.Duration) error {
func (c *Client) sniff(parentCtx context.Context, timeout time.Duration) error {
c.mu.RLock()
if !c.snifferEnabled {
c.mu.RUnlock()
@@ -863,7 +900,7 @@ func (c *Client) sniff(timeout time.Duration) error {
// Start sniffing on all found URLs
ch := make(chan []*conn, len(urls))
ctx, cancel := context.WithTimeout(context.Background(), timeout)
ctx, cancel := context.WithTimeout(parentCtx, timeout)
defer cancel()
for _, url := range urls {
@@ -879,6 +916,13 @@ func (c *Client) sniff(timeout time.Duration) error {
return nil
}
case <-ctx.Done():
if err := ctx.Err(); err != nil {
switch {
case IsContextErr(err):
return err
}
return errors.Wrapf(ErrNoClient, "sniff timeout: %v", err)
}
// We get here if no cluster responds in time
return errors.Wrap(ErrNoClient, "sniff timeout")
}
@@ -967,7 +1011,9 @@ func (c *Client) updateConns(conns []*conn) {
for _, conn := range conns {
var found bool
for _, oldConn := range c.conns {
if oldConn.NodeID() == conn.NodeID() {
// Notice that e.g. in a Kubernetes cluster the NodeID might be
// stable while the URL has changed.
if oldConn.NodeID() == conn.NodeID() && oldConn.URL() == conn.URL() {
// Take over the old connection
newConns = append(newConns, oldConn)
found = true
@@ -1003,7 +1049,7 @@ func (c *Client) healthchecker() {
c.healthcheckStop <- true
return
case <-ticker.C:
c.healthcheck(timeout, false)
c.healthcheck(context.Background(), timeout, false)
}
}
}
@@ -1012,7 +1058,7 @@ func (c *Client) healthchecker() {
// the node state, it marks connections as dead, sets them alive etc.
// If healthchecks are disabled and force is false, this is a no-op.
// The timeout specifies how long to wait for a response from Elasticsearch.
func (c *Client) healthcheck(timeout time.Duration, force bool) {
func (c *Client) healthcheck(parentCtx context.Context, timeout time.Duration, force bool) {
c.mu.RLock()
if !c.healthcheckEnabled && !force {
c.mu.RUnlock()
@@ -1029,7 +1075,7 @@ func (c *Client) healthcheck(timeout time.Duration, force bool) {
for _, conn := range conns {
// Run the HEAD request against ES with a timeout
ctx, cancel := context.WithTimeout(context.Background(), timeout)
ctx, cancel := context.WithTimeout(parentCtx, timeout)
defer cancel()
// Goroutine executes the HTTP request, returns an error and sets status
@@ -1077,7 +1123,7 @@ func (c *Client) healthcheck(timeout time.Duration, force bool) {
// startupHealthcheck is used at startup to check if the server is available
// at all.
func (c *Client) startupHealthcheck(timeout time.Duration) error {
func (c *Client) startupHealthcheck(parentCtx context.Context, timeout time.Duration) error {
c.mu.Lock()
urls := c.urls
basicAuth := c.basicAuth
@@ -1088,7 +1134,8 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
// If we don't get a connection after "timeout", we bail.
var lastErr error
start := time.Now()
for {
done := false
for !done {
for _, url := range urls {
req, err := http.NewRequest("HEAD", url, nil)
if err != nil {
@@ -1097,7 +1144,7 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
if basicAuth {
req.SetBasicAuth(basicAuthUsername, basicAuthPassword)
}
ctx, cancel := context.WithTimeout(req.Context(), timeout)
ctx, cancel := context.WithTimeout(parentCtx, timeout)
defer cancel()
req = req.WithContext(ctx)
res, err := c.c.Do(req)
@@ -1107,12 +1154,22 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error {
lastErr = err
}
}
time.Sleep(1 * time.Second)
if time.Since(start) > timeout {
select {
case <-parentCtx.Done():
lastErr = parentCtx.Err()
done = true
break
case <-time.After(1 * time.Second):
if time.Since(start) > timeout {
done = true
break
}
}
}
if lastErr != nil {
if IsContextErr(lastErr) {
return lastErr
}
return errors.Wrapf(ErrNoClient, "health check timeout: %v", lastErr)
}
return errors.Wrap(ErrNoClient, "health check timeout")
@@ -1175,48 +1232,24 @@ 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
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.
// 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) 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) {
func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions) (*Response, error) {
start := time.Now().UTC()
c.mu.RLock()
@@ -1256,7 +1289,7 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque
n++
if !retried {
// Force a healtcheck as all connections seem to be dead.
c.healthcheck(timeout, false)
c.healthcheck(ctx, timeout, false)
}
wait, ok, rerr := retrier.Retry(ctx, n, nil, nil, err)
if rerr != nil {
@@ -1287,6 +1320,14 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque
req.Header.Set("Content-Type", opt.ContentType)
}
if len(opt.Headers) > 0 {
for key, value := range opt.Headers {
for _, v := range value {
req.Header.Add(key, v)
}
}
}
// Set body
if opt.Body != nil {
err = req.SetBody(opt.Body, gzipEnabled)
@@ -1329,18 +1370,23 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque
// 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
// 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
}
@@ -1412,7 +1458,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/5.2/docs-reindex.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-reindex.html
// for details on the Reindex API.
func (c *Client) Reindex() *ReindexService {
return NewReindexService(c)
@@ -1439,11 +1485,6 @@ 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)
@@ -1477,11 +1518,6 @@ 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)
@@ -1591,6 +1627,15 @@ func (c *Client) Flush(indices ...string) *IndicesFlushService {
return NewIndicesFlushService(c).Index(indices...)
}
// SyncedFlush performs a synced flush.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-synced-flush.html
// for more details on synched flushes and how they differ from a normal
// Flush.
func (c *Client) SyncedFlush(indices ...string) *IndicesSyncedFlushService {
return NewIndicesSyncedFlushService(c).Index(indices...)
}
// Alias enables the caller to add and/or remove aliases.
func (c *Client) Alias() *AliasService {
return NewAliasService(c)
@@ -1601,24 +1646,6 @@ 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 {
@@ -1660,12 +1687,7 @@ func (c *Client) GetFieldMapping() *IndicesGetFieldMappingService {
// -- cat APIs --
// TODO cat aliases
// TODO cat allocation
// TODO cat count
// TODO cat fielddata
// TODO cat health
// TODO cat indices
// TODO cat master
// TODO cat nodes
// TODO cat pending tasks
@@ -1675,6 +1697,31 @@ func (c *Client) GetFieldMapping() *IndicesGetFieldMappingService {
// TODO cat shards
// TODO cat segments
// CatAliases returns information about aliases.
func (c *Client) CatAliases() *CatAliasesService {
return NewCatAliasesService(c)
}
// CatAllocation returns information about the allocation across nodes.
func (c *Client) CatAllocation() *CatAllocationService {
return NewCatAllocationService(c)
}
// CatCount returns document counts for indices.
func (c *Client) CatCount() *CatCountService {
return NewCatCountService(c)
}
// CatHealth returns information about cluster health.
func (c *Client) CatHealth() *CatHealthService {
return NewCatHealthService(c)
}
// CatIndices returns information about indices.
func (c *Client) CatIndices() *CatIndicesService {
return NewCatIndicesService(c)
}
// -- Ingest APIs --
// IngestPutPipeline adds pipelines and updates existing pipelines in
@@ -1706,6 +1753,12 @@ func (c *Client) ClusterHealth() *ClusterHealthService {
return NewClusterHealthService(c)
}
// ClusterReroute allows for manual changes to the allocation of
// individual shards in the cluster.
func (c *Client) ClusterReroute() *ClusterRerouteService {
return NewClusterRerouteService(c)
}
// ClusterState retrieves the state of the cluster.
func (c *Client) ClusterState() *ClusterStateService {
return NewClusterStateService(c)
@@ -1755,7 +1808,7 @@ func (c *Client) TasksGetTask() *TasksGetTaskService {
// TODO Snapshot Status
// SnapshotCreate creates a snapshot.
func (c *Client) SnapshotCreate(repository string, snapshot string) *SnapshotCreateService {
func (c *Client) SnapshotCreate(repository, snapshot string) *SnapshotCreateService {
return NewSnapshotCreateService(c).Repository(repository).Snapshot(snapshot)
}
@@ -1764,6 +1817,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, 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...)
@@ -1774,11 +1832,156 @@ func (c *Client) SnapshotGetRepository(repositories ...string) *SnapshotGetRepos
return NewSnapshotGetRepositoryService(c).Repository(repositories...)
}
// SnapshotGet lists snapshot for a repository.
func (c *Client) SnapshotGet(repository string) *SnapshotGetService {
return NewSnapshotGetService(c).Repository(repository)
}
// SnapshotVerifyRepository verifies a snapshot repository.
func (c *Client) SnapshotVerifyRepository(repository string) *SnapshotVerifyRepositoryService {
return NewSnapshotVerifyRepositoryService(c).Repository(repository)
}
// SnapshotRestore restores the specified indices from a given snapshot
func (c *Client) SnapshotRestore(repository, snapshot string) *SnapshotRestoreService {
return NewSnapshotRestoreService(c).Repository(repository).Snapshot(snapshot)
}
// -- Scripting APIs --
// GetScript reads a stored script in Elasticsearch.
// Use PutScript for storing a script.
func (c *Client) GetScript() *GetScriptService {
return NewGetScriptService(c)
}
// PutScript allows saving a stored script in Elasticsearch.
func (c *Client) PutScript() *PutScriptService {
return NewPutScriptService(c)
}
// DeleteScript allows removing a stored script from Elasticsearch.
func (c *Client) DeleteScript() *DeleteScriptService {
return NewDeleteScriptService(c)
}
// -- X-Pack General --
// XPackInfo gets information on the xpack plugins enabled on the cluster
func (c *Client) XPackInfo() *XPackInfoService {
return NewXPackInfoService(c)
}
// -- X-Pack Index Lifecycle Management --
// XPackIlmPutLifecycle adds or modifies an ilm policy.
func (c *Client) XPackIlmPutLifecycle() *XPackIlmPutLifecycleService {
return NewXPackIlmPutLifecycleService(c)
}
// XPackIlmGettLifecycle gets an ilm policy.
func (c *Client) XPackIlmGetLifecycle() *XPackIlmGetLifecycleService {
return NewXPackIlmGetLifecycleService(c)
}
// XPackIlmDeleteLifecycle deletes an ilm policy.
func (c *Client) XPackIlmDeleteLifecycle() *XPackIlmDeleteLifecycleService {
return NewXPackIlmDeleteLifecycleService(c)
}
// -- X-Pack Security --
// XPackSecurityGetRoleMapping gets a role mapping.
func (c *Client) XPackSecurityGetRoleMapping(roleMappingName string) *XPackSecurityGetRoleMappingService {
return NewXPackSecurityGetRoleMappingService(c).Name(roleMappingName)
}
// XPackSecurityPutRoleMapping adds a role mapping.
func (c *Client) XPackSecurityPutRoleMapping(roleMappingName string) *XPackSecurityPutRoleMappingService {
return NewXPackSecurityPutRoleMappingService(c).Name(roleMappingName)
}
// XPackSecurityDeleteRoleMapping deletes a role mapping.
func (c *Client) XPackSecurityDeleteRoleMapping(roleMappingName string) *XPackSecurityDeleteRoleMappingService {
return NewXPackSecurityDeleteRoleMappingService(c).Name(roleMappingName)
}
// XPackSecurityGetRole gets a role.
func (c *Client) XPackSecurityGetRole(roleName string) *XPackSecurityGetRoleService {
return NewXPackSecurityGetRoleService(c).Name(roleName)
}
// XPackSecurityPutRole adds a role.
func (c *Client) XPackSecurityPutRole(roleName string) *XPackSecurityPutRoleService {
return NewXPackSecurityPutRoleService(c).Name(roleName)
}
// XPackSecurityDeleteRole deletes a role.
func (c *Client) XPackSecurityDeleteRole(roleName string) *XPackSecurityDeleteRoleService {
return NewXPackSecurityDeleteRoleService(c).Name(roleName)
}
// TODO: Clear role cache API
// https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html
// -- X-Pack Watcher --
// XPackWatchPut adds a watch.
func (c *Client) XPackWatchPut(watchId string) *XPackWatcherPutWatchService {
return NewXPackWatcherPutWatchService(c).Id(watchId)
}
// XPackWatchGet gets a watch.
func (c *Client) XPackWatchGet(watchId string) *XPackWatcherGetWatchService {
return NewXPackWatcherGetWatchService(c).Id(watchId)
}
// XPackWatchDelete deletes a watch.
func (c *Client) XPackWatchDelete(watchId string) *XPackWatcherDeleteWatchService {
return NewXPackWatcherDeleteWatchService(c).Id(watchId)
}
// XPackWatchExecute executes a watch.
func (c *Client) XPackWatchExecute() *XPackWatcherExecuteWatchService {
return NewXPackWatcherExecuteWatchService(c)
}
// XPackWatchAck acknowledging a watch.
func (c *Client) XPackWatchAck(watchId string) *XPackWatcherAckWatchService {
return NewXPackWatcherAckWatchService(c).WatchId(watchId)
}
// XPackWatchActivate activates a watch.
func (c *Client) XPackWatchActivate(watchId string) *XPackWatcherActivateWatchService {
return NewXPackWatcherActivateWatchService(c).WatchId(watchId)
}
// XPackWatchDeactivate deactivates a watch.
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)
}
// XPackWatchStart starts a watch.
func (c *Client) XPackWatchStart() *XPackWatcherStartService {
return NewXPackWatcherStartService(c)
}
// XPackWatchStop stops a watch.
func (c *Client) XPackWatchStop() *XPackWatcherStopService {
return NewXPackWatcherStopService(c)
}
// XPackWatchRestart restarts a watch.
func (c *Client) XPackWatchRestart() *XPackWatcherRestartService {
return NewXPackWatcherRestartService(c)
}
// -- Helpers and shortcuts --
// ElasticsearchVersion returns the version number of Elasticsearch

View File

@@ -10,7 +10,7 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// ClusterHealthService allows to get a very simple status on the health of the cluster.
@@ -131,7 +131,7 @@ func (s *ClusterHealthService) 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.level != "" {
params.Set("level", s.level)
@@ -179,7 +179,11 @@ func (s *ClusterHealthService) Do(ctx context.Context) (*ClusterHealthResponse,
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

390
vendor/gopkg.in/olivere/elastic.v6/cluster_reroute.go generated vendored Normal file
View File

@@ -0,0 +1,390 @@
// 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"
"errors"
"fmt"
"net/url"
"strings"
)
// ClusterRerouteService allows for manual changes to the allocation of
// individual shards in the cluster. For example, a shard can be moved from
// one node to another explicitly, an allocation can be cancelled, and
// an unassigned shard can be explicitly allocated to a specific node.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-reroute.html
// for details.
type ClusterRerouteService struct {
client *Client
metrics []string
pretty bool
dryRun *bool
explain *bool
retryFailed *bool
masterTimeout string
timeout string
commands []AllocationCommand
body interface{}
}
// NewClusterRerouteService creates a new ClusterRerouteService.
func NewClusterRerouteService(client *Client) *ClusterRerouteService {
return &ClusterRerouteService{
client: client,
}
}
// Metric limits the information returned to the specified metric.
// It can be one of: "_all", "blocks", "metadata", "nodes", "routing_table", "master_node", "version".
// Defaults to all but metadata.
func (s *ClusterRerouteService) Metric(metrics ...string) *ClusterRerouteService {
s.metrics = append(s.metrics, metrics...)
return s
}
// DryRun indicates whether to simulate the operation only and return the
// resulting state.
func (s *ClusterRerouteService) DryRun(dryRun bool) *ClusterRerouteService {
s.dryRun = &dryRun
return s
}
// Explain, when set to true, returns an explanation of why the commands
// can or cannot be executed.
func (s *ClusterRerouteService) Explain(explain bool) *ClusterRerouteService {
s.explain = &explain
return s
}
// RetryFailed indicates whether to retry allocation of shards that are blocked
// due to too many subsequent allocation failures.
func (s *ClusterRerouteService) RetryFailed(retryFailed bool) *ClusterRerouteService {
s.retryFailed = &retryFailed
return s
}
// MasterTimeout specifies an explicit timeout for connection to master.
func (s *ClusterRerouteService) MasterTimeout(masterTimeout string) *ClusterRerouteService {
s.masterTimeout = masterTimeout
return s
}
// Timeout specifies an explicit operationtimeout.
func (s *ClusterRerouteService) Timeout(timeout string) *ClusterRerouteService {
s.timeout = timeout
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *ClusterRerouteService) Pretty(pretty bool) *ClusterRerouteService {
s.pretty = pretty
return s
}
// Add adds one or more commands to be executed.
func (s *ClusterRerouteService) Add(commands ...AllocationCommand) *ClusterRerouteService {
s.commands = append(s.commands, commands...)
return s
}
// Body specifies the body to be sent.
// If you specify Body, the commands passed via Add are ignored.
// In other words: Body takes precedence over Add.
func (s *ClusterRerouteService) Body(body interface{}) *ClusterRerouteService {
s.body = body
return s
}
// buildURL builds the URL for the operation.
func (s *ClusterRerouteService) buildURL() (string, url.Values, error) {
// Build URL
path := "/_cluster/reroute"
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "true")
}
if v := s.dryRun; v != nil {
params.Set("dry_run", fmt.Sprint(*v))
}
if v := s.explain; v != nil {
params.Set("explain", fmt.Sprint(*v))
}
if v := s.retryFailed; v != nil {
params.Set("retry_failed", fmt.Sprint(*v))
}
if len(s.metrics) > 0 {
params.Set("metric", strings.Join(s.metrics, ","))
}
if s.masterTimeout != "" {
params.Set("master_timeout", s.masterTimeout)
}
if s.timeout != "" {
params.Set("timeout", s.timeout)
}
if s.pretty {
params.Set("pretty", "true")
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *ClusterRerouteService) Validate() error {
if s.body == nil && len(s.commands) == 0 {
return errors.New("missing allocate commands or raw body")
}
return nil
}
// Do executes the operation.
func (s *ClusterRerouteService) Do(ctx context.Context) (*ClusterRerouteResponse, 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
}
// Setup HTTP request body
var body interface{}
if s.body != nil {
body = s.body
} else {
commands := make([]interface{}, len(s.commands))
for i, cmd := range s.commands {
src, err := cmd.Source()
if err != nil {
return nil, err
}
commands[i] = map[string]interface{}{
cmd.Name(): src,
}
}
query := make(map[string]interface{})
query["commands"] = commands
body = query
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(ClusterRerouteResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// ClusterRerouteResponse is the response of ClusterRerouteService.Do.
type ClusterRerouteResponse struct {
State *ClusterStateResponse `json:"state"`
Explanations []RerouteExplanation `json:"explanations,omitempty"`
}
// RerouteExplanation is returned in ClusterRerouteResponse if
// the "explain" parameter is set to "true".
type RerouteExplanation struct {
Command string `json:"command"`
Parameters map[string]interface{} `json:"parameters"`
Decisions []RerouteDecision `json:"decisions"`
}
// RerouteDecision is a decision the decider made while rerouting.
type RerouteDecision interface{}
// -- Allocation commands --
// AllocationCommand is a command to be executed in a call
// to Cluster Reroute API.
type AllocationCommand interface {
Name() string
Source() (interface{}, error)
}
var _ AllocationCommand = (*MoveAllocationCommand)(nil)
// MoveAllocationCommand moves a shard from a specific node to
// another node.
type MoveAllocationCommand struct {
index string
shardId int
fromNode string
toNode string
}
// NewMoveAllocationCommand creates a new MoveAllocationCommand.
func NewMoveAllocationCommand(index string, shardId int, fromNode, toNode string) *MoveAllocationCommand {
return &MoveAllocationCommand{
index: index,
shardId: shardId,
fromNode: fromNode,
toNode: toNode,
}
}
// Name of the command in a request to the Cluster Reroute API.
func (cmd *MoveAllocationCommand) Name() string { return "move" }
// Source generates the (inner) JSON to be used when serializing the command.
func (cmd *MoveAllocationCommand) Source() (interface{}, error) {
source := make(map[string]interface{})
source["index"] = cmd.index
source["shard"] = cmd.shardId
source["from_node"] = cmd.fromNode
source["to_node"] = cmd.toNode
return source, nil
}
var _ AllocationCommand = (*CancelAllocationCommand)(nil)
// CancelAllocationCommand cancels relocation, or recovery of a given shard on a node.
type CancelAllocationCommand struct {
index string
shardId int
node string
allowPrimary bool
}
// NewCancelAllocationCommand creates a new CancelAllocationCommand.
func NewCancelAllocationCommand(index string, shardId int, node string, allowPrimary bool) *CancelAllocationCommand {
return &CancelAllocationCommand{
index: index,
shardId: shardId,
node: node,
allowPrimary: allowPrimary,
}
}
// Name of the command in a request to the Cluster Reroute API.
func (cmd *CancelAllocationCommand) Name() string { return "cancel" }
// Source generates the (inner) JSON to be used when serializing the command.
func (cmd *CancelAllocationCommand) Source() (interface{}, error) {
source := make(map[string]interface{})
source["index"] = cmd.index
source["shard"] = cmd.shardId
source["node"] = cmd.node
source["allow_primary"] = cmd.allowPrimary
return source, nil
}
var _ AllocationCommand = (*AllocateStalePrimaryAllocationCommand)(nil)
// AllocateStalePrimaryAllocationCommand allocates an unassigned stale
// primary shard to a specific node. Use with extreme care as this will
// result in data loss. Allocation deciders are ignored.
type AllocateStalePrimaryAllocationCommand struct {
index string
shardId int
node string
acceptDataLoss bool
}
// NewAllocateStalePrimaryAllocationCommand creates a new
// AllocateStalePrimaryAllocationCommand.
func NewAllocateStalePrimaryAllocationCommand(index string, shardId int, node string, acceptDataLoss bool) *AllocateStalePrimaryAllocationCommand {
return &AllocateStalePrimaryAllocationCommand{
index: index,
shardId: shardId,
node: node,
acceptDataLoss: acceptDataLoss,
}
}
// Name of the command in a request to the Cluster Reroute API.
func (cmd *AllocateStalePrimaryAllocationCommand) Name() string { return "allocate_stale_primary" }
// Source generates the (inner) JSON to be used when serializing the command.
func (cmd *AllocateStalePrimaryAllocationCommand) Source() (interface{}, error) {
source := make(map[string]interface{})
source["index"] = cmd.index
source["shard"] = cmd.shardId
source["node"] = cmd.node
source["accept_data_loss"] = cmd.acceptDataLoss
return source, nil
}
var _ AllocationCommand = (*AllocateReplicaAllocationCommand)(nil)
// AllocateReplicaAllocationCommand allocates an unassigned replica shard
// to a specific node. Checks if allocation deciders allow allocation.
type AllocateReplicaAllocationCommand struct {
index string
shardId int
node string
}
// NewAllocateReplicaAllocationCommand creates a new
// AllocateReplicaAllocationCommand.
func NewAllocateReplicaAllocationCommand(index string, shardId int, node string) *AllocateReplicaAllocationCommand {
return &AllocateReplicaAllocationCommand{
index: index,
shardId: shardId,
node: node,
}
}
// Name of the command in a request to the Cluster Reroute API.
func (cmd *AllocateReplicaAllocationCommand) Name() string { return "allocate_replica" }
// Source generates the (inner) JSON to be used when serializing the command.
func (cmd *AllocateReplicaAllocationCommand) Source() (interface{}, error) {
source := make(map[string]interface{})
source["index"] = cmd.index
source["shard"] = cmd.shardId
source["node"] = cmd.node
return source, nil
}
// AllocateEmptyPrimaryAllocationCommand allocates an unassigned empty
// primary shard to a specific node. Use with extreme care as this will
// result in data loss. Allocation deciders are ignored.
type AllocateEmptyPrimaryAllocationCommand struct {
index string
shardId int
node string
acceptDataLoss bool
}
// NewAllocateEmptyPrimaryAllocationCommand creates a new
// AllocateEmptyPrimaryAllocationCommand.
func NewAllocateEmptyPrimaryAllocationCommand(index string, shardId int, node string, acceptDataLoss bool) *AllocateEmptyPrimaryAllocationCommand {
return &AllocateEmptyPrimaryAllocationCommand{
index: index,
shardId: shardId,
node: node,
acceptDataLoss: acceptDataLoss,
}
}
// Name of the command in a request to the Cluster Reroute API.
func (cmd *AllocateEmptyPrimaryAllocationCommand) Name() string { return "allocate_empty_primary" }
// Source generates the (inner) JSON to be used when serializing the command.
func (cmd *AllocateEmptyPrimaryAllocationCommand) Source() (interface{}, error) {
source := make(map[string]interface{})
source["index"] = cmd.index
source["shard"] = cmd.shardId
source["node"] = cmd.node
source["accept_data_loss"] = cmd.acceptDataLoss
return source, nil
}

View File

@@ -10,12 +10,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// ClusterStateService allows to get a comprehensive state information of the whole cluster.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-state.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-state.html
// for details.
type ClusterStateService struct {
client *Client
@@ -123,7 +123,7 @@ func (s *ClusterStateService) 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.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
@@ -165,7 +165,11 @@ func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, er
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -180,16 +184,16 @@ func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, er
// ClusterStateResponse is the response of ClusterStateService.Do.
type ClusterStateResponse struct {
ClusterName string `json:"cluster_name"`
Version int64 `json:"version"`
StateUUID string `json:"state_uuid"`
MasterNode string `json:"master_node"`
Blocks map[string]*clusterBlocks `json:"blocks"`
Nodes map[string]*discoveryNode `json:"nodes"`
Metadata *clusterStateMetadata `json:"metadata"`
RoutingTable map[string]*clusterStateRoutingTable `json:"routing_table"`
RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"`
Customs map[string]interface{} `json:"customs"`
ClusterName string `json:"cluster_name"`
Version int64 `json:"version"`
StateUUID string `json:"state_uuid"`
MasterNode string `json:"master_node"`
Blocks map[string]*clusterBlocks `json:"blocks"`
Nodes map[string]*discoveryNode `json:"nodes"`
Metadata *clusterStateMetadata `json:"metadata"`
RoutingTable *clusterStateRoutingTable `json:"routing_table"`
RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"`
Customs map[string]interface{} `json:"customs"`
}
type clusterBlocks struct {
@@ -235,10 +239,10 @@ type clusterStateRoutingNode struct {
}
type indexTemplateMetaData struct {
Template string `json:"template"` // e.g. "store-*"
Order int `json:"order"`
Settings map[string]interface{} `json:"settings"` // index settings
Mappings map[string]interface{} `json:"mappings"` // type name -> mapping
IndexPatterns []string `json:"index_patterns"` // e.g. ["store-*"]
Order int `json:"order"`
Settings map[string]interface{} `json:"settings"` // index settings
Mappings map[string]interface{} `json:"mappings"` // type name -> mapping
}
type indexMetaData struct {

View File

@@ -10,11 +10,11 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// ClusterStatsService is documented at
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-stats.html.
// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-stats.html.
type ClusterStatsService struct {
client *Client
pretty bool
@@ -78,7 +78,7 @@ func (s *ClusterStatsService) 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.flatSettings != nil {
params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings))
@@ -108,7 +108,11 @@ func (s *ClusterStatsService) Do(ctx context.Context) (*ClusterStatsResponse, er
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -125,23 +129,21 @@ func (s *ClusterStatsService) Do(ctx context.Context) (*ClusterStatsResponse, er
type ClusterStatsResponse struct {
Timestamp int64 `json:"timestamp"`
ClusterName string `json:"cluster_name"`
ClusterUUID string `json:"uuid"`
Status string `json:"status"`
ClusterUUID string `json:"cluster_uuid"`
Status string `json:"status,omitempty"` // e.g. green
Indices *ClusterStatsIndices `json:"indices"`
Nodes *ClusterStatsNodes `json:"nodes"`
}
type ClusterStatsIndices struct {
Count int `json:"count"`
Shards *ClusterStatsIndicesShards `json:"shards"`
Docs *ClusterStatsIndicesDocs `json:"docs"`
Store *ClusterStatsIndicesStore `json:"store"`
FieldData *ClusterStatsIndicesFieldData `json:"fielddata"`
FilterCache *ClusterStatsIndicesFilterCache `json:"filter_cache"`
IdCache *ClusterStatsIndicesIdCache `json:"id_cache"`
Completion *ClusterStatsIndicesCompletion `json:"completion"`
Segments *ClusterStatsIndicesSegments `json:"segments"`
Percolate *ClusterStatsIndicesPercolate `json:"percolate"`
Count int `json:"count"` // number of indices
Shards *ClusterStatsIndicesShards `json:"shards"`
Docs *ClusterStatsIndicesDocs `json:"docs"`
Store *ClusterStatsIndicesStore `json:"store"`
FieldData *ClusterStatsIndicesFieldData `json:"fielddata"`
QueryCache *ClusterStatsIndicesQueryCache `json:"query_cache"`
Completion *ClusterStatsIndicesCompletion `json:"completion"`
Segments *ClusterStatsIndicesSegments `json:"segments"`
}
type ClusterStatsIndicesShards struct {
@@ -175,10 +177,8 @@ type ClusterStatsIndicesDocs struct {
}
type ClusterStatsIndicesStore struct {
Size string `json:"size"` // e.g. "5.3gb"
SizeInBytes int64 `json:"size_in_bytes"`
ThrottleTime string `json:"throttle_time"` // e.g. "0s"
ThrottleTimeInMillis int64 `json:"throttle_time_in_millis"`
Size string `json:"size"` // e.g. "5.3gb"
SizeInBytes int64 `json:"size_in_bytes"`
}
type ClusterStatsIndicesFieldData struct {
@@ -188,52 +188,56 @@ type ClusterStatsIndicesFieldData struct {
Fields map[string]struct {
MemorySize string `json:"memory_size"` // e.g. "61.3kb"
MemorySizeInBytes int64 `json:"memory_size_in_bytes"`
} `json:"fields"`
} `json:"fields,omitempty"`
}
type ClusterStatsIndicesFilterCache struct {
type ClusterStatsIndicesQueryCache struct {
MemorySize string `json:"memory_size"` // e.g. "61.3kb"
MemorySizeInBytes int64 `json:"memory_size_in_bytes"`
TotalCount int64 `json:"total_count"`
HitCount int64 `json:"hit_count"`
MissCount int64 `json:"miss_count"`
CacheSize int64 `json:"cache_size"`
CacheCount int64 `json:"cache_count"`
Evictions int64 `json:"evictions"`
}
type ClusterStatsIndicesIdCache struct {
MemorySize string `json:"memory_size"` // e.g. "61.3kb"
MemorySizeInBytes int64 `json:"memory_size_in_bytes"`
}
type ClusterStatsIndicesCompletion struct {
Size string `json:"size"` // e.g. "61.3kb"
SizeInBytes int64 `json:"size_in_bytes"`
Fields map[string]struct {
Size string `json:"size"` // e.g. "61.3kb"
SizeInBytes int64 `json:"size_in_bytes"`
} `json:"fields"`
} `json:"fields,omitempty"`
}
type ClusterStatsIndicesSegments struct {
Count int64 `json:"count"`
Memory string `json:"memory"` // e.g. "61.3kb"
MemoryInBytes int64 `json:"memory_in_bytes"`
IndexWriterMemory string `json:"index_writer_memory"` // e.g. "61.3kb"
IndexWriterMemoryInBytes int64 `json:"index_writer_memory_in_bytes"`
IndexWriterMaxMemory string `json:"index_writer_max_memory"` // e.g. "61.3kb"
IndexWriterMaxMemoryInBytes int64 `json:"index_writer_max_memory_in_bytes"`
VersionMapMemory string `json:"version_map_memory"` // e.g. "61.3kb"
VersionMapMemoryInBytes int64 `json:"version_map_memory_in_bytes"`
FixedBitSet string `json:"fixed_bit_set"` // e.g. "61.3kb"
FixedBitSetInBytes int64 `json:"fixed_bit_set_memory_in_bytes"`
Count int64 `json:"count"`
Memory string `json:"memory"` // e.g. "61.3kb"
MemoryInBytes int64 `json:"memory_in_bytes"`
TermsMemory string `json:"terms_memory"` // e.g. "61.3kb"
TermsMemoryInBytes int64 `json:"terms_memory_in_bytes"`
StoredFieldsMemory string `json:"stored_fields_memory"` // e.g. "61.3kb"
StoredFieldsMemoryInBytes int64 `json:"stored_fields_memory_in_bytes"`
NormsMemory string `json:"norms_memory"` // e.g. "61.3kb"
NormsMemoryInBytes int64 `json:"norms_memory_in_bytes"`
PointsMemory string `json:"points_memory"` // e.g. "61.3kb"
PointsMemoryInBytes int64 `json:"points_memory_in_bytes"`
DocValuesMemory string `json:"doc_values_memory"` // e.g. "61.3kb"
DocValuesMemoryInBytes int64 `json:"doc_values_memory_in_bytes"`
IndexWriterMemory string `json:"index_writer_memory"` // e.g. "61.3kb"
IndexWriterMemoryInBytes int64 `json:"index_writer_memory_in_bytes"`
VersionMapMemory string `json:"version_map_memory"` // e.g. "61.3kb"
VersionMapMemoryInBytes int64 `json:"version_map_memory_in_bytes"`
FixedBitSet string `json:"fixed_bit_set"` // e.g. "61.3kb"
FixedBitSetInBytes int64 `json:"fixed_bit_set_memory_in_bytes"`
FileSizes map[string]*ClusterStatsIndicesSegmentsFile `json:"file_sizes"`
}
type ClusterStatsIndicesPercolate struct {
Total int64 `json:"total"`
// TODO(oe) The JSON tag here is wrong as of ES 1.5.2 it seems
Time string `json:"get_time"` // e.g. "1s"
TimeInBytes int64 `json:"time_in_millis"`
Current int64 `json:"current"`
MemorySize string `json:"memory_size"` // e.g. "61.3kb"
MemorySizeInBytes int64 `json:"memory_sitze_in_bytes"`
Queries int64 `json:"queries"`
type ClusterStatsIndicesSegmentsFile struct {
Size string `json:"size"` // e.g. "61.3kb"
SizeInBytes int64 `json:"size_in_bytes"`
Description string `json:"description,omitempty"`
}
// ---

View File

@@ -8,10 +8,9 @@ import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// CountService is a convenient service for determining the
@@ -216,7 +215,7 @@ func (s *CountService) 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.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
@@ -258,7 +257,7 @@ func (s *CountService) buildURL() (string, url.Values, error) {
params.Set("routing", s.routing)
}
if s.terminateAfter != nil {
params.Set("terminate_after", strconv.Itoa(*s.terminateAfter))
params.Set("terminate_after", fmt.Sprintf("%v", *s.terminateAfter))
}
return path, params, nil
}
@@ -298,7 +297,12 @@ func (s *CountService) Do(ctx context.Context) (int64, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return 0, err
}

View File

@@ -5,6 +5,7 @@
package elastic
import (
"bytes"
"encoding/json"
)
@@ -24,3 +25,14 @@ type DefaultDecoder struct{}
func (u *DefaultDecoder) Decode(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
// NumberDecoder uses json.NewDecoder, with UseNumber() enabled, from
// the Go standard library to decode JSON data.
type NumberDecoder struct{}
// Decode decodes with json.Unmarshal from the Go standard library.
func (u *NumberDecoder) Decode(data []byte, v interface{}) error {
dec := json.NewDecoder(bytes.NewReader(data))
dec.UseNumber()
return dec.Decode(v)
}

View File

@@ -7,17 +7,16 @@ package elastic
import (
"context"
"fmt"
"net/http"
"net/url"
"net/http"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// DeleteService allows to delete a typed JSON document from a specified
// index based on its id.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete.html
// for details.
type DeleteService struct {
client *Client
@@ -32,6 +31,8 @@ type DeleteService struct {
waitForActiveShards string
parent string
refresh string
ifSeqNo *int64
ifPrimaryTerm *int64
}
// NewDeleteService creates a new DeleteService.
@@ -100,11 +101,28 @@ func (s *DeleteService) Parent(parent string) *DeleteService {
}
// Refresh the index after performing the operation.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *DeleteService) Refresh(refresh string) *DeleteService {
s.refresh = refresh
return s
}
// IfSeqNo indicates to only perform the delete operation if the last
// operation that has changed the document has the specified sequence number.
func (s *DeleteService) IfSeqNo(seqNo int64) *DeleteService {
s.ifSeqNo = &seqNo
return s
}
// IfPrimaryTerm indicates to only perform the delete operation if the
// last operation that has changed the document has the specified primary term.
func (s *DeleteService) IfPrimaryTerm(primaryTerm int64) *DeleteService {
s.ifPrimaryTerm = &primaryTerm
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *DeleteService) Pretty(pretty bool) *DeleteService {
s.pretty = pretty
@@ -126,7 +144,7 @@ func (s *DeleteService) 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.refresh != "" {
params.Set("refresh", s.refresh)
@@ -149,6 +167,12 @@ func (s *DeleteService) buildURL() (string, url.Values, error) {
if s.parent != "" {
params.Set("parent", s.parent)
}
if v := s.ifSeqNo; v != nil {
params.Set("if_seq_no", fmt.Sprintf("%d", *v))
}
if v := s.ifPrimaryTerm; v != nil {
params.Set("if_primary_term", fmt.Sprintf("%d", *v))
}
return path, params, nil
}
@@ -186,7 +210,12 @@ func (s *DeleteService) Do(ctx context.Context) (*DeleteResponse, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil, http.StatusNotFound)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "DELETE",
Path: path,
Params: params,
IgnoreErrors: []int{http.StatusNotFound},
})
if err != nil {
return nil, err
}
@@ -219,5 +248,4 @@ type DeleteResponse struct {
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
ForcedRefresh bool `json:"forced_refresh,omitempty"`
Found bool `json:"found,omitempty"`
}

View File

@@ -7,14 +7,15 @@ package elastic
import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// DeleteByQueryService deletes documents that match a query.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete-by-query.html.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete-by-query.html.
type DeleteByQueryService struct {
client *Client
index []string
@@ -48,6 +49,7 @@ type DeleteByQueryService struct {
searchTimeout string
searchType string
size *int
slices interface{}
sort []string
stats []string
storedFields []string
@@ -240,6 +242,9 @@ func (s *DeleteByQueryService) Query(query Query) *DeleteByQueryService {
}
// Refresh indicates whether the effected indexes should be refreshed.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *DeleteByQueryService) Refresh(refresh string) *DeleteByQueryService {
s.refresh = refresh
return s
@@ -298,6 +303,16 @@ func (s *DeleteByQueryService) Size(size int) *DeleteByQueryService {
return s
}
// Slices represents the number of slices (default: 1).
// It used to be a number, but can be set to "auto" as of 6.7.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete-by-query.html#docs-delete-by-query-automatic-slice
// for details.
func (s *DeleteByQueryService) Slices(slices interface{}) *DeleteByQueryService {
s.slices = slices
return s
}
// Sort is a list of <field>:<direction> pairs.
func (s *DeleteByQueryService) Sort(sort ...string) *DeleteByQueryService {
s.sort = append(s.sort, sort...)
@@ -504,6 +519,9 @@ func (s *DeleteByQueryService) buildURL() (string, url.Values, error) {
if s.size != nil {
params.Set("size", fmt.Sprintf("%d", *s.size))
}
if s.slices != nil {
params.Set("slices", fmt.Sprintf("%v", s.slices))
}
if len(s.sort) > 0 {
params.Set("sort", strings.Join(s.sort, ","))
}
@@ -598,7 +616,12 @@ func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon
}
// Get response
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
@@ -611,19 +634,75 @@ func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon
return ret, nil
}
// DoAsync executes the delete-by-query operation asynchronously by starting a new task.
// Callers need to use the Task Management API to watch the outcome of the reindexing
// operation.
func (s *DeleteByQueryService) DoAsync(ctx context.Context) (*StartTaskResult, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
}
// DoAsync only makes sense with WaitForCompletion set to true
if s.waitForCompletion != nil && *s.waitForCompletion {
return nil, fmt.Errorf("cannot start a task with WaitForCompletion set to true")
}
f := false
s.waitForCompletion = &f
// Get URL for request
path, params, err := s.buildURL()
if err != nil {
return nil, err
}
// Set body if there is a query set
var body interface{}
if s.body != nil {
body = s.body
} else if s.query != nil {
src, err := s.query.Source()
if err != nil {
return nil, err
}
body = map[string]interface{}{
"query": src,
}
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(StartTaskResult)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// BulkIndexByScrollResponse is the outcome of executing Do with
// DeleteByQueryService and UpdateByQueryService.
type BulkIndexByScrollResponse struct {
Took int64 `json:"took"`
SliceId *int64 `json:"slice_id,omitempty"`
TimedOut bool `json:"timed_out"`
Total int64 `json:"total"`
Updated int64 `json:"updated,omitempty"`
Created int64 `json:"created,omitempty"`
Deleted int64 `json:"deleted"`
Batches int64 `json:"batches"`
VersionConflicts int64 `json:"version_conflicts"`
Noops int64 `json:"noops"`
Header http.Header `json:"-"`
Took int64 `json:"took"`
SliceId *int64 `json:"slice_id,omitempty"`
TimedOut bool `json:"timed_out"`
Total int64 `json:"total"`
Updated int64 `json:"updated,omitempty"`
Created int64 `json:"created,omitempty"`
Deleted int64 `json:"deleted"`
Batches int64 `json:"batches"`
VersionConflicts int64 `json:"version_conflicts"`
Noops int64 `json:"noops"`
Retries struct {
Bulk int64 `json:"bulk"`
Search int64 `json:"search"`

55
vendor/gopkg.in/olivere/elastic.v6/docker-compose.yml generated vendored Normal file
View File

@@ -0,0 +1,55 @@
version: '3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.2
hostname: elasticsearch
environment:
- cluster.name=elasticsearch
- bootstrap.memory_lock=true
# - http.host=0.0.0.0
# - transport.host=127.0.0.1
# - network.host=_local_
- network.publish_host=127.0.0.1
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
ulimits:
nproc: 65536
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
# volumes:
# - ./data/elasticsearch:/usr/share/elasticsearch/data
ports:
- 9200:9200
platinum:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.2
hostname: elasticsearch-platinum
environment:
- cluster.name=platinum
- bootstrap.memory_lock=true
- xpack.ilm.enabled=true
- 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_
- http.port=9210
- network.publish_host=127.0.0.1
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- ELASTIC_PASSWORD=elastic
ulimits:
nproc: 65536
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
# volumes:
# - ./data/elasticsearch-platinum:/usr/share/elasticsearch/data
ports:
- 9210:9210

42
vendor/gopkg.in/olivere/elastic.v6/docvalue_field.go generated vendored Normal file
View File

@@ -0,0 +1,42 @@
// 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
// DocvalueField represents a docvalue field, its name and
// its format (optional).
type DocvalueField struct {
Field string
Format string
}
// Source serializes the DocvalueField into JSON.
func (d DocvalueField) Source() (interface{}, error) {
if d.Format == "" {
return d.Field, nil
}
return map[string]interface{}{
"field": d.Field,
"format": d.Format,
}, nil
}
// DocvalueFields is a slice of DocvalueField instances.
type DocvalueFields []DocvalueField
// Source serializes the DocvalueFields into JSON.
func (d DocvalueFields) Source() (interface{}, error) {
if d == nil {
return nil, nil
}
v := make([]interface{}, 0)
for _, f := range d {
src, err := f.Source()
if err != nil {
return nil, err
}
v = append(v, src)
}
return v, nil
}

View File

@@ -137,6 +137,14 @@ func IsConflict(err interface{}) bool {
return IsStatusCode(err, http.StatusConflict)
}
// IsForbidden returns true if the given error indicates that Elasticsearch
// returned HTTP status 403. This happens e.g. due to a missing license.
// The err parameter can be of type *elastic.Error, elastic.Error,
// *http.Response or int (indicating the HTTP status code).
func IsForbidden(err interface{}) bool {
return IsStatusCode(err, http.StatusForbidden)
}
// IsStatusCode returns true if the given error indicates that the Elasticsearch
// operation returned the specified HTTP status code. The err parameter can be of
// type *http.Response, *Error, Error, or int (indicating the HTTP status code).

View File

@@ -10,12 +10,12 @@ import (
"net/http"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// ExistsService checks for the existence of a document using HEAD.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-get.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-get.html
// for details.
type ExistsService struct {
client *Client
@@ -69,6 +69,9 @@ func (s *ExistsService) Realtime(realtime bool) *ExistsService {
}
// Refresh the shard containing the document before performing the operation.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *ExistsService) Refresh(refresh string) *ExistsService {
s.refresh = refresh
return s
@@ -107,7 +110,7 @@ func (s *ExistsService) 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.realtime != nil {
params.Set("realtime", fmt.Sprintf("%v", *s.realtime))
@@ -159,7 +162,12 @@ func (s *ExistsService) Do(ctx context.Context) (bool, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "HEAD",
Path: path,
Params: params,
IgnoreErrors: []int{404},
})
if err != nil {
return false, err
}

View File

@@ -10,12 +10,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// ExplainService computes a score explanation for a query and
// a specific document.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-explain.html.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-explain.html.
type ExplainService struct {
client *Client
pretty bool
@@ -208,7 +208,7 @@ func (s *ExplainService) buildURL() (string, url.Values, error) {
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if len(s.xSource) > 0 {
params.Set("_source", strings.Join(s.xSource, ","))
@@ -298,7 +298,12 @@ func (s *ExplainService) Do(ctx context.Context) (*ExplainResponse, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}

View File

@@ -14,7 +14,7 @@ import (
// with various endpoints, e.g. when searching for documents, retrieving
// individual documents, or even updating documents.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-source-filtering.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
// for details.
type FetchSourceContext struct {
fetchSource bool

View File

@@ -11,12 +11,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// FieldCapsService allows retrieving the capabilities of fields among multiple indices.
//
// See http://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-caps.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-field-caps.html
// for details
type FieldCapsService struct {
client *Client
@@ -152,7 +152,13 @@ func (s *FieldCapsService) Do(ctx context.Context) (*FieldCapsResponse, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, body, http.StatusNotFound)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
IgnoreErrors: []int{http.StatusNotFound},
})
if err != nil {
return nil, err
}
@@ -182,9 +188,13 @@ type FieldCapsRequest struct {
// FieldCapsResponse contains field capabilities.
type FieldCapsResponse struct {
Fields map[string]FieldCaps `json:"fields,omitempty"`
Fields map[string]FieldCapsType `json:"fields,omitempty"` // Name -> type -> caps
}
// FieldCapsType represents a mapping from type (e.g. keyword)
// to capabilities.
type FieldCapsType map[string]FieldCaps // type -> caps
// FieldCaps contains capabilities of an individual field.
type FieldCaps struct {
Type string `json:"type"`

View File

@@ -5,6 +5,7 @@
package elastic
import (
"encoding/json"
"fmt"
"strconv"
"strings"
@@ -24,6 +25,11 @@ func (pt *GeoPoint) Source() map[string]float64 {
}
}
// MarshalJSON encodes the GeoPoint to JSON.
func (pt *GeoPoint) MarshalJSON() ([]byte, error) {
return json.Marshal(pt.Source())
}
// GeoPointFromLatLon initializes a new GeoPoint by latitude and longitude.
func GeoPointFromLatLon(lat, lon float64) *GeoPoint {
return &GeoPoint{Lat: lat, Lon: lon}

View File

@@ -11,13 +11,13 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// GetService allows to get a typed JSON document from the index based
// on its id.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-get.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-get.html
// for details.
type GetService struct {
client *Client
@@ -103,6 +103,9 @@ func (s *GetService) FetchSourceContext(fetchSourceContext *FetchSourceContext)
}
// Refresh the shard containing the document before performing the operation.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *GetService) Refresh(refresh string) *GetService {
s.refresh = refresh
return s
@@ -172,7 +175,7 @@ func (s *GetService) 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.routing != "" {
params.Set("routing", s.routing)
@@ -223,7 +226,11 @@ func (s *GetService) Do(ctx context.Context) (*GetResult, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -240,16 +247,18 @@ func (s *GetService) Do(ctx context.Context) (*GetResult, error) {
// GetResult is the outcome of GetService.Do.
type GetResult struct {
Index string `json:"_index"` // index meta field
Type string `json:"_type"` // type meta field
Id string `json:"_id"` // id meta field
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
Source *json.RawMessage `json:"_source,omitempty"`
Found bool `json:"found,omitempty"`
Fields map[string]interface{} `json:"fields,omitempty"`
Index string `json:"_index"` // index meta field
Type string `json:"_type"` // type meta field
Id string `json:"_id"` // id meta field
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
SeqNo *int64 `json:"_seq_no"`
PrimaryTerm *int64 `json:"_primary_term"`
Source *json.RawMessage `json:"_source,omitempty"`
Found bool `json:"found,omitempty"`
Fields map[string]interface{} `json:"fields,omitempty"`
//Error string `json:"error,omitempty"` // used only in MultiGet
// TODO double-check that MultiGet now returns details error information
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet

View File

@@ -6,7 +6,7 @@ package elastic
// Highlight allows highlighting search results on one or more fields.
// For details, see:
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-highlighting.html
// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html
type Highlight struct {
fields []*HighlighterField
tagsSchema *string

View File

@@ -9,13 +9,13 @@ import (
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndexService adds or updates a typed JSON document in a specified index,
// making it searchable.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html
// for details.
type IndexService struct {
client *Client
@@ -34,6 +34,8 @@ type IndexService struct {
refresh string
waitForActiveShards string
pipeline string
ifSeqNo *int64
ifPrimaryTerm *int64
bodyJson interface{}
bodyString string
}
@@ -80,6 +82,9 @@ func (s *IndexService) Pipeline(pipeline string) *IndexService {
}
// Refresh the index after performing the operation.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html
// for details.
func (s *IndexService) Refresh(refresh string) *IndexService {
s.refresh = refresh
return s
@@ -139,6 +144,20 @@ func (s *IndexService) VersionType(versionType string) *IndexService {
return s
}
// IfSeqNo indicates to only perform the index operation if the last
// operation that has changed the document has the specified sequence number.
func (s *IndexService) IfSeqNo(seqNo int64) *IndexService {
s.ifSeqNo = &seqNo
return s
}
// IfPrimaryTerm indicates to only perform the index operation if the
// last operation that has changed the document has the specified primary term.
func (s *IndexService) IfPrimaryTerm(primaryTerm int64) *IndexService {
s.ifPrimaryTerm = &primaryTerm
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *IndexService) Pretty(pretty bool) *IndexService {
s.pretty = pretty
@@ -172,7 +191,7 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) {
})
} else {
// Automatic ID generation
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-creation
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#index-creation
method = "POST"
path, err = uritemplates.Expand("/{index}/{type}/", map[string]string{
"index": s.index,
@@ -186,7 +205,7 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) {
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if s.waitForActiveShards != "" {
params.Set("wait_for_active_shards", s.waitForActiveShards)
@@ -221,6 +240,12 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) {
if s.versionType != "" {
params.Set("version_type", s.versionType)
}
if v := s.ifSeqNo; v != nil {
params.Set("if_seq_no", fmt.Sprintf("%d", *v))
}
if v := s.ifPrimaryTerm; v != nil {
params.Set("if_primary_term", fmt.Sprintf("%d", *v))
}
return method, path, params, nil
}
@@ -264,7 +289,12 @@ func (s *IndexService) Do(ctx context.Context) (*IndexResponse, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, method, path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: method,
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}

View File

@@ -9,13 +9,13 @@ import (
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesAnalyzeService performs the analysis process on a text and returns
// the tokens breakdown of the text.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-analyze.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-analyze.html
// for detail.
type IndicesAnalyzeService struct {
client *Client
@@ -152,7 +152,7 @@ func (s *IndicesAnalyzeService) 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.format != "" {
params.Set("format", s.format)
@@ -185,11 +185,16 @@ func (s *IndicesAnalyzeService) Do(ctx context.Context) (*IndicesAnalyzeResponse
} else {
// Request parameters are deprecated in 5.1.1, and we must use a JSON
// structure in the body to pass the parameters.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-analyze.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-analyze.html
body = s.request
}
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
@@ -233,11 +238,12 @@ type IndicesAnalyzeResponse struct {
}
type IndicesAnalyzeResponseToken struct {
Token string `json:"token"`
StartOffset int `json:"start_offset"`
EndOffset int `json:"end_offset"`
Type string `json:"type"`
Position int `json:"position"`
Token string `json:"token"`
StartOffset int `json:"start_offset"`
EndOffset int `json:"end_offset"`
Type string `json:"type"`
Position int `json:"position"`
PositionLength int `json:"positionLength"` // seems to be wrong in 6.8 (no snake_case), see https://github.com/elastic/elasticsearch/blob/6.8/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeResponse.java
}
type IndicesAnalyzeResponseDetail struct {

View File

@@ -9,12 +9,12 @@ import (
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesCloseService closes an index.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-open-close.html
// for details.
type IndicesCloseService struct {
client *Client
@@ -134,7 +134,11 @@ func (s *IndicesCloseService) Do(ctx context.Context) (*IndicesCloseResponse, er
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -149,5 +153,7 @@ func (s *IndicesCloseService) Do(ctx context.Context) (*IndicesCloseResponse, er
// IndicesCloseResponse is the response of IndicesCloseService.Do.
type IndicesCloseResponse struct {
Acknowledged bool `json:"acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -9,21 +9,23 @@ import (
"errors"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesCreateService creates a new index.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-create-index.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-create-index.html
// for details.
type IndicesCreateService struct {
client *Client
pretty bool
index string
timeout string
masterTimeout string
bodyJson interface{}
bodyString string
client *Client
pretty bool
index string
timeout string
masterTimeout string
includeTypeName *bool
updateAllTypes *bool
bodyJson interface{}
bodyString string
}
// NewIndicesCreateService returns a new IndicesCreateService.
@@ -49,6 +51,20 @@ func (s *IndicesCreateService) MasterTimeout(masterTimeout string) *IndicesCreat
return s
}
// IncludeTypeName indicates whether a type should be expected in the
// body of the mappings.
func (s *IndicesCreateService) IncludeTypeName(include bool) *IndicesCreateService {
s.includeTypeName = &include
return s
}
// UpdateAllTypes indicates whether to update the mapping for all fields
// with the same name across all types or not.
func (s *IndicesCreateService) UpdateAllTypes(update bool) *IndicesCreateService {
s.updateAllTypes = &update
return s
}
// Body specifies the configuration of the index as a string.
// It is an alias for BodyString.
func (b *IndicesCreateService) Body(body string) *IndicesCreateService {
@@ -91,7 +107,7 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er
params := make(url.Values)
if b.pretty {
params.Set("pretty", "1")
params.Set("pretty", "true")
}
if b.masterTimeout != "" {
params.Set("master_timeout", b.masterTimeout)
@@ -99,6 +115,20 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er
if b.timeout != "" {
params.Set("timeout", b.timeout)
}
if v := b.includeTypeName; v != nil {
if *v {
params.Set("include_type_name", "true")
} else {
params.Set("include_type_name", "false")
}
}
if v := b.updateAllTypes; v != nil && *v {
if *v {
params.Set("update_all_types", "true")
} else {
params.Set("update_all_types", "false")
}
}
// Setup HTTP request body
var body interface{}
@@ -109,7 +139,12 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er
}
// Get response
res, err := b.client.PerformRequest(ctx, "PUT", path, params, body)
res, err := b.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
@@ -125,6 +160,7 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er
// IndicesCreateResult is the outcome of creating a new index.
type IndicesCreateResult struct {
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -10,12 +10,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesDeleteService allows to delete existing indices.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-delete-index.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-delete-index.html
// for details.
type IndicesDeleteService struct {
client *Client
@@ -71,7 +71,7 @@ func (s *IndicesDeleteService) 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.timeout != "" {
params.Set("timeout", s.timeout)
@@ -108,7 +108,11 @@ func (s *IndicesDeleteService) Do(ctx context.Context) (*IndicesDeleteResponse,
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "DELETE",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -9,11 +9,11 @@ import (
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesDeleteTemplateService deletes index templates.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html.
type IndicesDeleteTemplateService struct {
client *Client
pretty bool
@@ -66,7 +66,7 @@ func (s *IndicesDeleteTemplateService) 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.timeout != "" {
params.Set("timeout", s.timeout)
@@ -103,7 +103,11 @@ func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTe
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "DELETE",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -118,5 +122,7 @@ func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTe
// IndicesDeleteTemplateResponse is the response of IndicesDeleteTemplateService.Do.
type IndicesDeleteTemplateResponse struct {
Acknowledged bool `json:"acknowledged,omitempty"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -11,12 +11,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesExistsService checks if an index or indices exist or not.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-exists.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-exists.html
// for details.
type IndicesExistsService struct {
client *Client
@@ -90,7 +90,7 @@ func (s *IndicesExistsService) 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.local != nil {
params.Set("local", fmt.Sprintf("%v", *s.local))
@@ -133,7 +133,12 @@ func (s *IndicesExistsService) Do(ctx context.Context) (bool, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "HEAD",
Path: path,
Params: params,
IgnoreErrors: []int{404},
})
if err != nil {
return false, err
}

View File

@@ -10,7 +10,7 @@ import (
"net/http"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesExistsTemplateService checks if a given template exists.
@@ -62,7 +62,7 @@ func (s *IndicesExistsTemplateService) 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.local != nil {
params.Set("local", fmt.Sprintf("%v", *s.local))
@@ -96,7 +96,12 @@ func (s *IndicesExistsTemplateService) Do(ctx context.Context) (bool, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "HEAD",
Path: path,
Params: params,
IgnoreErrors: []int{404},
})
if err != nil {
return false, err
}

View File

@@ -11,12 +11,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesExistsTypeService checks if one or more types exist in one or more indices.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-types-exists.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-types-exists.html
// for details.
type IndicesExistsTypeService struct {
client *Client
@@ -97,7 +97,7 @@ func (s *IndicesExistsTypeService) 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.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
@@ -143,7 +143,12 @@ func (s *IndicesExistsTypeService) Do(ctx context.Context) (bool, error) {
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "HEAD",
Path: path,
Params: params,
IgnoreErrors: []int{404},
})
if err != nil {
return false, err
}

View File

@@ -10,14 +10,14 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// Flush allows to flush one or more indices. The flush process of an index
// basically frees memory from the index by flushing data to the index
// storage and clearing the internal transaction log.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-flush.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-flush.html
// for details.
type IndicesFlushService struct {
client *Client
@@ -110,7 +110,7 @@ func (s *IndicesFlushService) 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.force != nil {
params.Set("force", fmt.Sprintf("%v", *s.force))
@@ -149,7 +149,11 @@ func (s *IndicesFlushService) Do(ctx context.Context) (*IndicesFlushResponse, er
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -0,0 +1,230 @@
// 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"
"strings"
"github.com/olivere/elastic/uritemplates"
)
// IndicesSyncedFlushService performs a normal flush, then adds a generated
// unique marked (sync_id) to all shards.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-synced-flush.html
// for details.
type IndicesSyncedFlushService struct {
client *Client
pretty bool
index []string
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
}
// NewIndicesSyncedFlushService creates a new IndicesSyncedFlushService.
func NewIndicesSyncedFlushService(client *Client) *IndicesSyncedFlushService {
return &IndicesSyncedFlushService{
client: client,
}
}
// Index is a list of index names; use `_all` or empty string for all indices.
func (s *IndicesSyncedFlushService) Index(indices ...string) *IndicesSyncedFlushService {
s.index = append(s.index, indices...)
return s
}
// IgnoreUnavailable indicates whether specified concrete indices should be
// ignored when unavailable (missing or closed).
func (s *IndicesSyncedFlushService) IgnoreUnavailable(ignoreUnavailable bool) *IndicesSyncedFlushService {
s.ignoreUnavailable = &ignoreUnavailable
return s
}
// AllowNoIndices indicates whether to ignore if a wildcard indices expression
// resolves into no concrete indices. (This includes `_all` string or when
// no indices have been specified).
func (s *IndicesSyncedFlushService) AllowNoIndices(allowNoIndices bool) *IndicesSyncedFlushService {
s.allowNoIndices = &allowNoIndices
return s
}
// ExpandWildcards specifies whether to expand wildcard expression to
// concrete indices that are open, closed or both..
func (s *IndicesSyncedFlushService) ExpandWildcards(expandWildcards string) *IndicesSyncedFlushService {
s.expandWildcards = expandWildcards
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *IndicesSyncedFlushService) Pretty(pretty bool) *IndicesSyncedFlushService {
s.pretty = pretty
return s
}
// buildURL builds the URL for the operation.
func (s *IndicesSyncedFlushService) buildURL() (string, url.Values, error) {
// Build URL
var err error
var path string
if len(s.index) > 0 {
path, err = uritemplates.Expand("/{index}/_flush/synced", map[string]string{
"index": strings.Join(s.index, ","),
})
} else {
path = "/_flush/synced"
}
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "true")
}
if s.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
}
if s.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
}
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
return path, params, nil
}
// Validate checks if the operation is valid.
func (s *IndicesSyncedFlushService) Validate() error {
return nil
}
// Do executes the service.
func (s *IndicesSyncedFlushService) Do(ctx context.Context) (*IndicesSyncedFlushResponse, 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: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
ret := new(IndicesSyncedFlushResponse)
if err := s.client.decoder.Decode(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a flush request.
// IndicesSyncedFlushResponse is the outcome of a synched flush call.
type IndicesSyncedFlushResponse struct {
Shards *ShardsInfo `json:"_shards"`
Index map[string]*IndicesShardsSyncedFlushResult `json:"-"`
// TODO Add information about the indices here from the root level
// It looks like this:
// {
// "_shards" : {
// "total" : 4,
// "successful" : 4,
// "failed" : 0
// },
// "elastic-test" : {
// "total" : 1,
// "successful" : 1,
// "failed" : 0
// },
// "elastic-test2" : {
// "total" : 1,
// "successful" : 1,
// "failed" : 0
// },
// "elastic-orders" : {
// "total" : 1,
// "successful" : 1,
// "failed" : 0
// },
// "elastic-nosource-test" : {
// "total" : 1,
// "successful" : 1,
// "failed" : 0
// }
// }
}
// IndicesShardsSyncedFlushResult represents synced flush information about
// a specific index.
type IndicesShardsSyncedFlushResult struct {
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
Failures []IndicesShardsSyncedFlushResultFailure `json:"failures,omitempty"`
}
// IndicesShardsSyncedFlushResultFailure represents a failure of a synced
// flush operation.
type IndicesShardsSyncedFlushResultFailure struct {
Shard int `json:"shard"`
Reason string `json:"reason"`
Routing struct {
State string `json:"state"`
Primary bool `json:"primary"`
Node string `json:"node"`
RelocatingNode *string `json:"relocating_node"`
Shard int `json:"shard"`
Index string `json:"index"`
ExpectedShardSizeInBytes int64 `json:"expected_shard_size_in_bytes,omitempty"`
// recoverySource
// allocationId
// unassignedInfo
} `json:"routing"`
}
// UnmarshalJSON parses the output from Synced Flush API.
func (resp *IndicesSyncedFlushResponse) UnmarshalJSON(data []byte) error {
m := make(map[string]json.RawMessage)
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
resp.Index = make(map[string]*IndicesShardsSyncedFlushResult)
for k, v := range m {
if k == "_shards" {
if err := json.Unmarshal(v, &resp.Shards); err != nil {
return err
}
} else {
ix := new(IndicesShardsSyncedFlushResult)
if err := json.Unmarshal(v, &ix); err != nil {
return err
}
resp.Index[k] = ix
}
}
return nil
}

View File

@@ -10,7 +10,7 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesForcemergeService allows to force merging of one or more indices.
@@ -30,7 +30,6 @@ type IndicesForcemergeService struct {
ignoreUnavailable *bool
maxNumSegments interface{}
onlyExpungeDeletes *bool
operationThreading interface{}
}
// NewIndicesForcemergeService creates a new IndicesForcemergeService.
@@ -94,11 +93,6 @@ func (s *IndicesForcemergeService) OnlyExpungeDeletes(onlyExpungeDeletes bool) *
return s
}
func (s *IndicesForcemergeService) OperationThreading(operationThreading interface{}) *IndicesForcemergeService {
s.operationThreading = operationThreading
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *IndicesForcemergeService) Pretty(pretty bool) *IndicesForcemergeService {
s.pretty = pretty
@@ -125,7 +119,7 @@ func (s *IndicesForcemergeService) 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.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
@@ -145,9 +139,6 @@ func (s *IndicesForcemergeService) buildURL() (string, url.Values, error) {
if s.onlyExpungeDeletes != nil {
params.Set("only_expunge_deletes", fmt.Sprintf("%v", *s.onlyExpungeDeletes))
}
if s.operationThreading != nil {
params.Set("operation_threading", fmt.Sprintf("%v", s.operationThreading))
}
return path, params, nil
}
@@ -170,7 +161,11 @@ func (s *IndicesForcemergeService) Do(ctx context.Context) (*IndicesForcemergeRe
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -10,12 +10,12 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesGetService retrieves information about one or more indices.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-index.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html
// for more details.
type IndicesGetService struct {
client *Client
@@ -131,7 +131,7 @@ func (s *IndicesGetService) 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.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
@@ -180,7 +180,11 @@ func (s *IndicesGetService) Do(ctx context.Context) (map[string]*IndicesGetRespo
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -10,14 +10,16 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// AliasesService returns the aliases associated with one or more indices.
// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-aliases.html.
// AliasesService returns the aliases associated with one or more indices, or the
// indices associated with one or more aliases, or a combination of those filters.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-aliases.html.
type AliasesService struct {
client *Client
index []string
alias []string
pretty bool
}
@@ -41,21 +43,31 @@ func (s *AliasesService) Index(index ...string) *AliasesService {
return s
}
// Alias adds one or more aliases.
func (s *AliasesService) Alias(alias ...string) *AliasesService {
s.alias = append(s.alias, alias...)
return s
}
// buildURL builds the URL for the operation.
func (s *AliasesService) buildURL() (string, url.Values, error) {
var err error
var path string
if len(s.index) > 0 {
path, err = uritemplates.Expand("/{index}/_aliases", map[string]string{
path, err = uritemplates.Expand("/{index}/_alias/{alias}", map[string]string{
"index": strings.Join(s.index, ","),
"alias": strings.Join(s.alias, ","),
})
} else {
path = "/_aliases"
path, err = uritemplates.Expand("/_alias/{alias}", map[string]string{
"alias": strings.Join(s.alias, ","),
})
}
if err != nil {
return "", url.Values{}, err
}
path = strings.TrimSuffix(path, "/")
// Add query string parameters
params := url.Values{}
@@ -72,7 +84,11 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) {
}
// Get response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -88,7 +104,11 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) {
// ...
// },
// }
indexMap := make(map[string]interface{})
indexMap := make(map[string]struct {
Aliases map[string]struct {
IsWriteIndex bool `json:"is_write_index"`
} `json:"aliases"`
})
if err := s.client.decoder.Decode(res.Body, &indexMap); err != nil {
return nil, err
}
@@ -98,21 +118,19 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) {
Indices: make(map[string]indexResult),
}
for indexName, indexData := range indexMap {
if indexData.Aliases == nil {
continue
}
indexOut, found := ret.Indices[indexName]
if !found {
indexOut = indexResult{Aliases: make([]aliasResult, 0)}
}
// { "aliases" : { ... } }
indexDataMap, ok := indexData.(map[string]interface{})
if ok {
aliasesData, ok := indexDataMap["aliases"].(map[string]interface{})
if ok {
for aliasName, _ := range aliasesData {
aliasRes := aliasResult{AliasName: aliasName}
indexOut.Aliases = append(indexOut.Aliases, aliasRes)
}
}
for aliasName, aliasData := range indexData.Aliases {
aliasRes := aliasResult{AliasName: aliasName, IsWriteIndex: aliasData.IsWriteIndex}
indexOut.Aliases = append(indexOut.Aliases, aliasRes)
}
ret.Indices[indexName] = indexOut
@@ -123,6 +141,7 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) {
// -- Result of an alias request.
// AliasesResult is the outcome of calling AliasesService.Do.
type AliasesResult struct {
Indices map[string]indexResult
}
@@ -132,9 +151,11 @@ type indexResult struct {
}
type aliasResult struct {
AliasName string
AliasName string
IsWriteIndex bool
}
// IndicesByAlias returns all indices given a specific alias name.
func (ar AliasesResult) IndicesByAlias(aliasName string) []string {
var indices []string
for indexName, indexInfo := range ar.Indices {
@@ -147,6 +168,7 @@ func (ar AliasesResult) IndicesByAlias(aliasName string) []string {
return indices
}
// HasAlias returns true if the index has a specific alias.
func (ir indexResult) HasAlias(aliasName string) bool {
for _, alias := range ir.Aliases {
if alias.AliasName == aliasName {

View File

@@ -10,13 +10,13 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesGetFieldMappingService retrieves the mapping definitions for the fields in an index
// or index/type.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-field-mapping.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-field-mapping.html
// for details.
type IndicesGetFieldMappingService struct {
client *Client
@@ -131,7 +131,7 @@ func (s *IndicesGetFieldMappingService) 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.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
@@ -170,7 +170,11 @@ func (s *IndicesGetFieldMappingService) Do(ctx context.Context) (map[string]inte
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -10,13 +10,13 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesGetMappingService retrieves the mapping definitions for an index or
// index/type.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-mapping.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-mapping.html
// for details.
type IndicesGetMappingService struct {
client *Client
@@ -119,7 +119,7 @@ func (s *IndicesGetMappingService) 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.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
@@ -156,7 +156,11 @@ func (s *IndicesGetMappingService) Do(ctx context.Context) (map[string]interface
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -10,13 +10,13 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesGetSettingsService allows to retrieve settings of one
// or more indices.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-settings.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-settings.html
// for more details.
type IndicesGetSettingsService struct {
client *Client
@@ -125,7 +125,7 @@ func (s *IndicesGetSettingsService) 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.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
@@ -164,7 +164,11 @@ func (s *IndicesGetSettingsService) Do(ctx context.Context) (map[string]*Indices
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}

View File

@@ -10,11 +10,11 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesGetTemplateService returns an index template.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html.
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html.
type IndicesGetTemplateService struct {
client *Client
pretty bool
@@ -75,7 +75,7 @@ func (s *IndicesGetTemplateService) 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.flatSettings != nil {
params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings))
@@ -105,7 +105,11 @@ func (s *IndicesGetTemplateService) Do(ctx context.Context) (map[string]*Indices
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "GET",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -120,10 +124,10 @@ func (s *IndicesGetTemplateService) Do(ctx context.Context) (map[string]*Indices
// IndicesGetTemplateResponse is the response of IndicesGetTemplateService.Do.
type IndicesGetTemplateResponse struct {
Order int `json:"order,omitempty"`
Version int `json:"version,omitempty"`
Template string `json:"template,omitempty"`
Settings map[string]interface{} `json:"settings,omitempty"`
Mappings map[string]interface{} `json:"mappings,omitempty"`
Aliases map[string]interface{} `json:"aliases,omitempty"`
Order int `json:"order,omitempty"`
Version int `json:"version,omitempty"`
IndexPatterns []string `json:"index_patterns,omitempty"`
Settings map[string]interface{} `json:"settings,omitempty"`
Mappings map[string]interface{} `json:"mappings,omitempty"`
Aliases map[string]interface{} `json:"aliases,omitempty"`
}

View File

@@ -9,22 +9,23 @@ import (
"fmt"
"net/url"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesOpenService opens an index.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-open-close.html
// for details.
type IndicesOpenService struct {
client *Client
pretty bool
index string
timeout string
masterTimeout string
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
client *Client
pretty bool
index string
timeout string
masterTimeout string
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
waitForActiveShards string
}
// NewIndicesOpenService creates and initializes a new IndicesOpenService.
@@ -72,6 +73,14 @@ func (s *IndicesOpenService) ExpandWildcards(expandWildcards string) *IndicesOpe
return s
}
// WaitForActiveShards specifies the number of shards that must be allocated
// before the Open operation returns. Valid values are "all" or an integer
// between 0 and number_of_replicas+1 (default: 0)
func (s *IndicesOpenService) WaitForActiveShards(waitForActiveShards string) *IndicesOpenService {
s.waitForActiveShards = waitForActiveShards
return s
}
// Pretty indicates that the JSON response be indented and human readable.
func (s *IndicesOpenService) Pretty(pretty bool) *IndicesOpenService {
s.pretty = pretty
@@ -91,7 +100,7 @@ func (s *IndicesOpenService) 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.timeout != "" {
params.Set("timeout", s.timeout)
@@ -108,6 +117,9 @@ func (s *IndicesOpenService) buildURL() (string, url.Values, error) {
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
if s.waitForActiveShards != "" {
params.Set("wait_for_active_shards", s.waitForActiveShards)
}
return path, params, nil
}
@@ -138,7 +150,11 @@ func (s *IndicesOpenService) Do(ctx context.Context) (*IndicesOpenResponse, erro
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "POST", path, params, nil)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
@@ -153,5 +169,7 @@ func (s *IndicesOpenService) Do(ctx context.Context) (*IndicesOpenResponse, erro
// IndicesOpenResponse is the response of IndicesOpenService.Do.
type IndicesOpenResponse struct {
Acknowledged bool `json:"acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -26,6 +26,7 @@ type AliasAddAction struct {
routing string
searchRouting string
indexRouting string
isWriteIndex *bool
}
// NewAliasAddAction returns an action to add an alias.
@@ -76,6 +77,12 @@ func (a *AliasAddAction) SearchRouting(routing ...string) *AliasAddAction {
return a
}
// IsWriteIndex associates an is_write_index flag to the alias.
func (a *AliasAddAction) IsWriteIndex(flag bool) *AliasAddAction {
a.isWriteIndex = &flag
return a
}
// Validate checks if the operation is valid.
func (a *AliasAddAction) Validate() error {
var invalid []string
@@ -88,6 +95,9 @@ func (a *AliasAddAction) Validate() error {
if len(invalid) > 0 {
return fmt.Errorf("missing required fields: %v", invalid)
}
if a.isWriteIndex != nil && len(a.index) > 1 {
return fmt.Errorf("more than 1 target index specified in operation with 'is_write_index' flag present")
}
return nil
}
@@ -123,6 +133,9 @@ func (a *AliasAddAction) Source() (interface{}, error) {
if len(a.searchRouting) > 0 {
act["search_routing"] = a.searchRouting
}
if a.isWriteIndex != nil {
act["is_write_index"] = *a.isWriteIndex
}
return src, nil
}
@@ -189,10 +202,43 @@ func (a *AliasRemoveAction) Source() (interface{}, error) {
return src, nil
}
// AliasRemoveIndexAction is an action to remove an index during an alias
// operation.
type AliasRemoveIndexAction struct {
index string // index name
}
// NewAliasRemoveIndexAction returns an action to remove an index.
func NewAliasRemoveIndexAction(index string) *AliasRemoveIndexAction {
return &AliasRemoveIndexAction{
index: index,
}
}
// Validate checks if the operation is valid.
func (a *AliasRemoveIndexAction) Validate() error {
if a.index == "" {
return fmt.Errorf("missing required field: index")
}
return nil
}
// Source returns the JSON-serializable data.
func (a *AliasRemoveIndexAction) Source() (interface{}, error) {
if err := a.Validate(); err != nil {
return nil, err
}
src := make(map[string]interface{})
act := make(map[string]interface{})
src["remove_index"] = act
act["index"] = a.index
return src, nil
}
// -- Service --
// AliasService enables users to add or remove an alias.
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-aliases.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-aliases.html
// for details.
type AliasService struct {
client *Client
@@ -274,7 +320,12 @@ func (s *AliasService) Do(ctx context.Context) (*AliasResult, error) {
body["actions"] = actions
// Get response
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
@@ -291,5 +342,7 @@ func (s *AliasService) Do(ctx context.Context) (*AliasResult, error) {
// AliasResult is the outcome of calling Do on AliasService.
type AliasResult struct {
Acknowledged bool `json:"acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

View File

@@ -10,13 +10,13 @@ import (
"net/url"
"strings"
"gopkg.in/olivere/elastic.v5/uritemplates"
"github.com/olivere/elastic/uritemplates"
)
// IndicesPutMappingService allows to register specific mapping definition
// for a specific type.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-put-mapping.html
// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-put-mapping.html
// for details.
type IndicesPutMappingService struct {
client *Client
@@ -27,6 +27,7 @@ type IndicesPutMappingService struct {
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
includeTypeName *bool
updateAllTypes *bool
timeout string
bodyJson map[string]interface{}
@@ -94,10 +95,17 @@ func (s *IndicesPutMappingService) ExpandWildcards(expandWildcards string) *Indi
return s
}
// UpdateAllTypes, if true, indicates that all fields that span multiple indices
// should be updated (default: false).
func (s *IndicesPutMappingService) UpdateAllTypes(updateAllTypes bool) *IndicesPutMappingService {
s.updateAllTypes = &updateAllTypes
// IncludeTypeName indicates whether to update the mapping for all fields
// with the same name across all types or not.
func (s *IndicesPutMappingService) IncludeTypeName(include bool) *IndicesPutMappingService {
s.includeTypeName = &include
return s
}
// UpdateAllTypes indicates whether to update the mapping for all fields
// with the same name across all types or not.
func (s *IndicesPutMappingService) UpdateAllTypes(update bool) *IndicesPutMappingService {
s.updateAllTypes = &update
return s
}
@@ -142,7 +150,7 @@ func (s *IndicesPutMappingService) 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.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
@@ -153,8 +161,19 @@ func (s *IndicesPutMappingService) buildURL() (string, url.Values, error) {
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
if s.updateAllTypes != nil {
params.Set("update_all_types", fmt.Sprintf("%v", *s.updateAllTypes))
if v := s.includeTypeName; v != nil {
if *v {
params.Set("include_type_name", "true")
} else {
params.Set("include_type_name", "false")
}
}
if v := s.updateAllTypes; v != nil && *v {
if *v {
params.Set("update_all_types", "true")
} else {
params.Set("update_all_types", "false")
}
}
if s.timeout != "" {
params.Set("timeout", s.timeout)
@@ -202,7 +221,12 @@ func (s *IndicesPutMappingService) Do(ctx context.Context) (*PutMappingResponse,
}
// Get HTTP response
res, err := s.client.PerformRequest(ctx, "PUT", path, params, body)
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
Method: "PUT",
Path: path,
Params: params,
Body: body,
})
if err != nil {
return nil, err
}
@@ -217,5 +241,7 @@ func (s *IndicesPutMappingService) Do(ctx context.Context) (*PutMappingResponse,
// PutMappingResponse is the response of IndicesPutMappingService.Do.
type PutMappingResponse struct {
Acknowledged bool `json:"acknowledged"`
Acknowledged bool `json:"acknowledged"`
ShardsAcknowledged bool `json:"shards_acknowledged"`
Index string `json:"index,omitempty"`
}

Some files were not shown because too many files have changed in this diff Show More