Merge pull request #656 from huanggze/log-2.1

logging: use elastic client for go
This commit is contained in:
KubeSphere CI Bot
2019-09-09 13:34:09 +08:00
committed by GitHub
799 changed files with 174665 additions and 69 deletions

6
go.mod
View File

@@ -32,6 +32,9 @@ require (
github.com/docker/go-connections v0.3.0 // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/elastic/go-elasticsearch/v5 v5.6.1
github.com/elastic/go-elasticsearch/v6 v6.8.2
github.com/elastic/go-elasticsearch/v7 v7.3.0
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2 // indirect
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 // indirect
@@ -210,6 +213,9 @@ replace (
github.com/eapache/go-resiliency => github.com/eapache/go-resiliency v1.1.0
github.com/eapache/go-xerial-snappy => github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21
github.com/eapache/queue => github.com/eapache/queue v1.1.0
github.com/elastic/go-elasticsearch/v5 => github.com/elastic/go-elasticsearch/v5 v5.6.1
github.com/elastic/go-elasticsearch/v6 => github.com/elastic/go-elasticsearch/v6 v6.8.2
github.com/elastic/go-elasticsearch/v7 => github.com/elastic/go-elasticsearch/v7 v7.3.0
github.com/elazarl/go-bindata-assetfs => github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/elazarl/goproxy => github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2
github.com/elazarl/goproxy/ext => github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2

6
go.sum
View File

@@ -93,6 +93,12 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/elastic/go-elasticsearch/v5 v5.6.1 h1:RnL2wcXepOT5SdoKMMO1j1OBX0vxHYbBtkQNL2E3xs4=
github.com/elastic/go-elasticsearch/v5 v5.6.1/go.mod h1:r7uV7HidpfkYh7D8SB4lkS13TNlNy3oa5GNmTZvuVqY=
github.com/elastic/go-elasticsearch/v6 v6.8.2 h1:rp5DGrd63V5c6nHLjF6QEXUpZSvs0+QM3ld7m9VhV2g=
github.com/elastic/go-elasticsearch/v6 v6.8.2/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/elastic/go-elasticsearch/v7 v7.3.0 h1:H29Nqf9cB9dVxX6LwS+zTDC2D4t9s+8dK8ln4HPS9rw=
github.com/elastic/go-elasticsearch/v7 v7.3.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2 h1:aZtFdDNWY/yH86JPR2WX/PN63635VsE/f/nXNPAbYxY=

View File

@@ -333,7 +333,7 @@ func syncFluentbitCRDOutputWithConfigMap(outputs []fb.OutputPlugin) error {
}
// Parse es host, port and index
func ParseEsOutputParams(params []fb.Parameter) *es.ESConfigs {
func ParseEsOutputParams(params []fb.Parameter) *es.Config {
var (
isEsFound bool
@@ -377,5 +377,5 @@ func ParseEsOutputParams(params []fb.Parameter) *es.ESConfigs {
}
}
return &es.ESConfigs{Host: host, Port: port, Index: index}
return &es.Config{Host: host, Port: port, Index: index}
}

View File

@@ -13,11 +13,9 @@ limitations under the License.
package esclient
import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/glog"
"io/ioutil"
"net/http"
"strconv"
"strings"
@@ -30,28 +28,31 @@ import (
var jsonIter = jsoniter.ConfigCompatibleWithStandardLibrary
var (
mu sync.RWMutex
esConfigs *ESConfigs
mu sync.Mutex
config *Config
client Client
)
type ESConfigs struct {
type Config struct {
Host string
Port string
Index string
VersionMajor string
}
func readESConfigs() *ESConfigs {
mu.RLock()
defer mu.RUnlock()
return esConfigs
}
func (configs *ESConfigs) WriteESConfigs() {
func (cfg *Config) WriteESConfigs() {
mu.Lock()
defer mu.Unlock()
esConfigs = configs
config = cfg
if err := detectVersionMajor(config); err != nil {
glog.Errorln(err)
client = nil
return
}
client = NewForConfig(config)
}
type Request struct {
@@ -303,7 +304,8 @@ type Shards struct {
}
type Hits struct {
Total int64 `json:"total"`
// As of ElasticSearch v7.x, hits.total is changed
Total interface{} `json:"total"`
Hits []Hit `json:"hits"`
}
@@ -427,7 +429,7 @@ func calcTimestamp(input string) int64 {
return ret
}
func parseQueryResult(operation int, param QueryParameters, body []byte, query []byte) *QueryResult {
func parseQueryResult(operation int, param QueryParameters, body []byte) *QueryResult {
var queryResult QueryResult
var response Response
@@ -457,7 +459,7 @@ func parseQueryResult(operation int, param QueryParameters, body []byte, query [
switch operation {
case OperationQuery:
var readResult ReadResult
readResult.Total = response.Hits.Total
readResult.Total = client.GetTotalHitCount(response.Hits.Total)
readResult.From = param.From
readResult.Size = param.Size
for _, hit := range response.Hits.Hits {
@@ -476,24 +478,24 @@ func parseQueryResult(operation int, param QueryParameters, body []byte, query [
case OperationStatistics:
var statisticsResponse StatisticsResponseAggregations
err := jsonIter.Unmarshal(response.Aggregations, &statisticsResponse)
if err != nil {
if err != nil && response.Aggregations != nil {
glog.Errorln(err)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = err.Error()
return &queryResult
}
queryResult.Statistics = &StatisticsResult{Containers: statisticsResponse.ContainerCount.Value, Logs: response.Hits.Total}
queryResult.Statistics = &StatisticsResult{Containers: statisticsResponse.ContainerCount.Value, Logs: client.GetTotalHitCount(response.Hits.Total)}
case OperationHistogram:
var histogramResult HistogramResult
histogramResult.Total = response.Hits.Total
histogramResult.Total = client.GetTotalHitCount(response.Hits.Total)
histogramResult.StartTime = calcTimestamp(param.StartTime)
histogramResult.EndTime = calcTimestamp(param.EndTime)
histogramResult.Interval = param.Interval
var histogramAggregations HistogramAggregations
err := jsonIter.Unmarshal(response.Aggregations, &histogramAggregations)
if err != nil {
if err != nil && response.Aggregations != nil {
glog.Errorln(err)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = err.Error()
@@ -541,58 +543,25 @@ type QueryParameters struct {
Size int64
}
func stubResult() *QueryResult {
var queryResult QueryResult
queryResult.Status = http.StatusOK
return &queryResult
}
func Query(param QueryParameters) *QueryResult {
var queryResult *QueryResult
client := &http.Client{}
var queryResult = new(QueryResult)
if client == nil {
queryResult.Status = http.StatusBadRequest
queryResult.Error = fmt.Sprintf("Invalid elasticsearch address: host=%s, port=%s", config.Host, config.Port)
return queryResult
}
operation, query, err := createQueryRequest(param)
if err != nil {
queryResult = new(QueryResult)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = err.Error()
return queryResult
}
es := readESConfigs()
if es == nil {
queryResult = new(QueryResult)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = "Elasticsearch configurations not found. Please check if they are properly configured."
return queryResult
}
url := fmt.Sprintf("http://%s:%s/%s*/_search", es.Host, es.Port, es.Index)
request, err := http.NewRequest("GET", url, bytes.NewBuffer(query))
if err != nil {
glog.Errorln(err)
queryResult = new(QueryResult)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = err.Error()
return queryResult
}
request.Header.Set("Content-Type", "application/json; charset=utf-8")
response, err := client.Do(request)
if err != nil {
glog.Errorln(err)
queryResult = new(QueryResult)
queryResult.Status = http.StatusInternalServerError
queryResult.Error = err.Error()
return queryResult
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
body, err := client.Search(query)
if err != nil {
glog.Errorln(err)
queryResult = new(QueryResult)
@@ -601,7 +570,7 @@ func Query(param QueryParameters) *QueryResult {
return queryResult
}
queryResult = parseQueryResult(operation, param, body, query)
queryResult = parseQueryResult(operation, param, body)
return queryResult
}

View File

@@ -0,0 +1,72 @@
package esclient
import (
"context"
"encoding/json"
"fmt"
v5 "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch/versions/v5"
v6 "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch/versions/v6"
v7 "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch/versions/v7"
"strings"
)
const (
ElasticV5 = "5"
ElasticV6 = "6"
ElasticV7 = "7"
)
type Client interface {
// Perform Search API
Search(body []byte) ([]byte, error)
GetTotalHitCount(v interface{}) int64
}
func NewForConfig(cfg *Config) Client {
address := fmt.Sprintf("http://%s:%s", cfg.Host, cfg.Port)
index := cfg.Index
switch cfg.VersionMajor {
case ElasticV5:
return v5.New(address, index)
case ElasticV6:
return v6.New(address, index)
case ElasticV7:
return v7.New(address, index)
default:
return nil
}
}
func detectVersionMajor(cfg *Config) error {
// Info APIs are backward compatible with versions of v5.x, v6.x and v7.x
address := fmt.Sprintf("http://%s:%s", cfg.Host, cfg.Port)
es := v6.New(address, "")
res, err := es.Client.Info(
es.Client.Info.WithContext(context.Background()),
)
if err != nil {
return err
}
defer res.Body.Close()
var b map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&b); err != nil {
return err
}
if res.IsError() {
// Print the response status and error information.
e, _ := b["error"].(map[string]interface{})
return fmt.Errorf("[%s] %s: %s", res.Status(), e["type"], e["reason"])
}
// get the major version
version, _ := b["version"].(map[string]interface{})
number, _ := version["number"].(string)
if number == "" {
return fmt.Errorf("failed to detect elastic version number")
}
cfg.VersionMajor = strings.Split(number, ".")[0]
return nil
}

View File

@@ -0,0 +1,55 @@
package v5
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v5"
"io/ioutil"
)
type Elastic struct {
client *elasticsearch.Client
index string
}
func New(address string, index string) Elastic {
client, _ := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
})
return Elastic{client: client, index: index}
}
func (e Elastic) Search(body []byte) ([]byte, error) {
response, err := e.client.Search(
e.client.Search.WithContext(context.Background()),
e.client.Search.WithIndex(fmt.Sprintf("%s*", e.index)),
e.client.Search.WithBody(bytes.NewBuffer(body)),
)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.IsError() {
var e map[string]interface{}
if err := json.NewDecoder(response.Body).Decode(&e); err != nil {
return nil, err
} else {
// Print the response status and error information.
e, _ := e["error"].(map[string]interface{})
return nil, fmt.Errorf("[%s] %s: %s", response.Status(), e["type"], e["reason"])
}
}
return ioutil.ReadAll(response.Body)
}
func (e Elastic) GetTotalHitCount(v interface{}) int64 {
f, _ := v.(float64)
return int64(f)
}

View File

@@ -0,0 +1,55 @@
package v6
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v6"
"io/ioutil"
)
type Elastic struct {
Client *elasticsearch.Client
index string
}
func New(address string, index string) Elastic {
client, _ := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
})
return Elastic{Client: client, index: index}
}
func (e Elastic) Search(body []byte) ([]byte, error) {
response, err := e.Client.Search(
e.Client.Search.WithContext(context.Background()),
e.Client.Search.WithIndex(fmt.Sprintf("%s*", e.index)),
e.Client.Search.WithBody(bytes.NewBuffer(body)),
)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.IsError() {
var e map[string]interface{}
if err := json.NewDecoder(response.Body).Decode(&e); err != nil {
return nil, err
} else {
// Print the response status and error information.
e, _ := e["error"].(map[string]interface{})
return nil, fmt.Errorf("[%s] %s: %s", response.Status(), e["type"], e["reason"])
}
}
return ioutil.ReadAll(response.Body)
}
func (e Elastic) GetTotalHitCount(v interface{}) int64 {
f, _ := v.(float64)
return int64(f)
}

View File

@@ -0,0 +1,57 @@
package v7
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v7"
"io/ioutil"
)
type Elastic struct {
client *elasticsearch.Client
index string
}
func New(address string, index string) Elastic {
client, _ := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
})
return Elastic{client: client, index: index}
}
func (e Elastic) Search(body []byte) ([]byte, error) {
response, err := e.client.Search(
e.client.Search.WithContext(context.Background()),
e.client.Search.WithIndex(fmt.Sprintf("%s*", e.index)),
e.client.Search.WithTrackTotalHits(true),
e.client.Search.WithBody(bytes.NewBuffer(body)),
)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.IsError() {
var e map[string]interface{}
if err := json.NewDecoder(response.Body).Decode(&e); err != nil {
return nil, err
} else {
// Print the response status and error information.
e, _ := e["error"].(map[string]interface{})
return nil, fmt.Errorf("[%s] %s: %s", response.Status(), e["type"], e["reason"])
}
}
return ioutil.ReadAll(response.Body)
}
func (e Elastic) GetTotalHitCount(v interface{}) int64 {
m, _ := v.(map[string]interface{})
f, _ := m["value"].(float64)
return int64(f)
}

View File

@@ -0,0 +1,8 @@
comment: off
coverage:
status:
patch: off
ignore:
- "esapi/api.*.go"

View File

@@ -0,0 +1,2 @@
.git/
tmp/

View File

@@ -0,0 +1,2 @@
tmp/
*.test

View File

@@ -0,0 +1,172 @@
dist: xenial
language: go
services:
- docker
branches:
only:
- master
- travis
install: true
matrix:
fast_finish: true
allow_failures:
- os: windows
include:
- name: Unit Tests | Linux, go:stable, gomod=on
os: linux
go: stable
env: GO111MODULE=on TEST_SUITE=unit
script:
- go mod verify
- go build -v ./...
- make lint
- gotestsum --format=short-verbose --junitfile=/tmp/unit-junit.xml -- -coverprofile=/tmp/unit.cov -tags='unit' -timeout=1h -v ./...
after_script:
- test -f /tmp/unit.cov && bash <(curl -s https://codecov.io/bash) -f /tmp/unit.cov
- name: Unit Tests | Linux, go:stable, gomod=off
os: linux
go: stable
env: GO111MODULE=off TEST_SUITE=unit
before_install:
- go get -u golang.org/x/lint/golint
- go get -u gotest.tools/gotestsum
install:
- go get -v ./...
script:
- go build -v ./...
- make lint
- gotestsum --format=short-verbose --junitfile=/tmp/unit-junit.xml -- -tags='unit' -timeout=1h -v ./...
- name: Unit Tests | OS X, go:stable, gomod=on
os: osx
go: stable
env: GO111MODULE=on TEST_SUITE=unit
script:
- go mod verify
- go build -v ./...
- gotestsum --format=short-verbose --junitfile=/tmp/unit-junit.xml -- --tags='unit' --timeout=1h -v ./...
- name: Unit Tests | Windows, go:stable, gomod=on
os: windows
go: stable
env: GO111MODULE=on TEST_SUITE=unit
script:
- go mod verify
- go build -v ./...
- gotestsum --format=short-verbose --junitfile=/tmp/unit-junit.xml -- -tags='unit' -timeout=1h -v ./...
- name: Unit Tests | Linux, go:master, gomod=on
os: linux
go: master
env: GO111MODULE=on TEST_SUITE=unit
script:
- go mod verify
- go build -v ./...
- make lint
- gotestsum --format=short-verbose --junitfile=/tmp/unit-junit.xml -- -tags='unit' -timeout=1h -v ./...
- name: Unit Tests | Docker/Linux, golang:1-alpine
os: linux
env: TEST_SUITE=unit
before_install: true
script:
- grep 'FROM' Dockerfile
- docker build --file Dockerfile --tag elastic/go-elasticsearch .
- echo $(($(docker image inspect -f '{{.Size}}' elastic/go-elasticsearch)/(1000*1000)))MB
- docker run -ti elastic/go-elasticsearch make lint
- docker run -ti elastic/go-elasticsearch make test
- name: Integration Tests | Linux, go:stable
os: linux
go: stable
env: GO111MODULE=on TEST_SUITE=integration-client
before_script:
- docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.0-SNAPSHOT
- docker network inspect elasticsearch > /dev/null || docker network create elasticsearch;
- |
docker run \
--name es-integration-client \
--network elasticsearch \
--env "cluster.name=es-integration-client" \
--env "discovery.type=single-node" \
--env "bootstrap.memory_lock=true" \
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--env ES_JAVA_OPTS="-Xms1g -Xmx1g" \
--volume es-integration-client-data:/usr/share/elasticsearch/data \
--publish 9200:9200 \
--ulimit nofile=65536:65536 \
--ulimit memlock=-1:-1 \
--detach \
--rm \
docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.0-SNAPSHOT
- docker run --network elasticsearch --rm appropriate/curl --max-time 120 --retry 120 --retry-delay 1 --retry-connrefused --show-error --silent http://es-integration-client:9200
script:
- gotestsum --format=short-verbose --junitfile=/tmp/integration-report.xml -- -race -cover -coverprofile=/tmp/integration-client.cov -tags='integration' -timeout=1h github.com/elastic/go-elasticsearch
after_script:
- test -f /tmp/integration-client.cov && bash <(curl -s https://codecov.io/bash) -f /tmp/integration-client.cov
- name: Integration Tests, API | Linux, go:stable
os: linux
go: stable
env: GO111MODULE=on TEST_SUITE=integration-api
before_script:
- docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.0-SNAPSHOT
- docker network inspect elasticsearch > /dev/null || docker network create elasticsearch;
- |
docker run \
--name es-integration-api \
--network elasticsearch \
--env "cluster.name=es-integration-api" \
--env "discovery.type=single-node" \
--env "bootstrap.memory_lock=true" \
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--env "node.attr.testattr=test" \
--env "path.repo=/tmp" \
--env "repositories.url.allowed_urls=http://snapshot.test*" \
--env ES_JAVA_OPTS="-Xms1g -Xmx1g" \
--volume es-integration-api-data:/usr/share/elasticsearch/data \
--publish 9200:9200 \
--ulimit nofile=65536:65536 \
--ulimit memlock=-1:-1 \
--detach \
--rm \
docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.0-SNAPSHOT
- docker run --network elasticsearch --rm appropriate/curl --max-time 120 --retry 120 --retry-delay 1 --retry-connrefused --show-error --silent http://es-integration-api:9200
script:
- curl -s http://localhost:9200 | jq -r '.version.build_hash' > .elasticsearch_build_hash && cat .elasticsearch_build_hash
# ------ Download Elasticsearch -----------------------------------------------------------
- echo -e "\e[33;1mDownload Elasticsearch Git source @ $(cat .elasticsearch_build_hash)\e[0m" && echo -en 'travis_fold:start:script.dl_es_src\\r'
- echo https://github.com/elastic/elasticsearch/archive/$(cat .elasticsearch_build_hash).zip
- |
curl -sSL --retry 3 -o elasticsearch-$(cat .elasticsearch_build_hash).zip https://github.com/elastic/elasticsearch/archive/$(cat .elasticsearch_build_hash).zip && \
unzip -q -o elasticsearch-$(cat .elasticsearch_build_hash).zip '*.properties' '*.json' '*.yml' -d /tmp && \
mv /tmp/elasticsearch-$(cat .elasticsearch_build_hash)* /tmp/elasticsearch
- echo -en 'travis_fold:end:script.dl_es_src'
# ------ Generate API registry ------------------------------------------------------------
- echo -e "\e[33;1mGenerate API registry\e[0m" && echo -en 'travis_fold:start:script.gen_api_reg\\r\n'
- cd ${TRAVIS_HOME}/gopath/src/github.com/elastic/go-elasticsearch/internal/cmd/generate && ELASTICSEARCH_BUILD_HASH=$(cat ../../../.elasticsearch_build_hash) PACKAGE_PATH=${TRAVIS_HOME}/gopath/src/github.com/elastic/go-elasticsearch/esapi go generate -v ./...
- echo -en 'travis_fold:end:script.gen_api_reg'
# ------ Generate Go test files -----------------------------------------------------------
- echo -e "\e[33;1mGenerate Go test files\e[0m" && echo -en 'travis_fold:start:script.gen_test_files\\r'
- cd ${TRAVIS_HOME}/gopath/src/github.com/elastic/go-elasticsearch/internal/cmd/generate && ELASTICSEARCH_BUILD_HASH=$(cat ../../../.elasticsearch_build_hash) go run main.go apitests --input '/tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test/**/*.yml' --output=../../../esapi/test
- echo -en 'travis_fold:end:script.gen_test_files'
# ------ Run tests -----------------------------------------------------------------------
- cd ${TRAVIS_HOME}/gopath/src/github.com/elastic/go-elasticsearch/esapi/test && time gotestsum --format=short-verbose --junitfile=/tmp/integration-api-report.xml -- -coverpkg=github.com/elastic/go-elasticsearch/esapi -coverprofile=/tmp/integration-api.cov -tags='integration' -timeout=1h ./...
after_script:
- test -f /tmp/integration-api.cov && bash <(curl -s https://codecov.io/bash) -f /tmp/integration-api.cov
before_install:
- GO111MODULE=off go get -u golang.org/x/lint/golint
- GO111MODULE=off go get -u gotest.tools/gotestsum
script: echo "TODO > test $TEST_SUITE ($TRAVIS_OS_NAME)"
notifications:
email: true

View File

@@ -0,0 +1,22 @@
# $ docker build --file Dockerfile --tag elastic/go-elasticsearch .
#
# $ docker run -it --network elasticsearch --volume $PWD/tmp:/tmp:rw --rm elastic/go-elasticsearch gotestsum --format=short-verbose --junitfile=/tmp/integration-junit.xml -- --cover --coverprofile=/tmp/integration-coverage.out --tags='integration' -v ./...
#
ARG VERSION=1-alpine
FROM golang:${VERSION}
RUN apk add --no-cache --quiet make curl git jq unzip tree && \
go get -u golang.org/x/lint/golint && \
curl -sSL --retry 3 --retry-connrefused https://github.com/gotestyourself/gotestsum/releases/download/v0.3.2/gotestsum_0.3.2_linux_amd64.tar.gz | tar -xz -C /usr/local/bin gotestsum
VOLUME ["/tmp"]
ENV CGO_ENABLED=0
ENV TERM xterm-256color
WORKDIR /go-elasticsearch
COPY . .
RUN go mod download && go mod vendor && \
cd internal/cmd/generate && go mod download && go mod vendor

201
vendor/github.com/elastic/go-elasticsearch/v5/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018 Elasticsearch BV
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

355
vendor/github.com/elastic/go-elasticsearch/v5/Makefile generated vendored Normal file
View File

@@ -0,0 +1,355 @@
##@ Test
test-unit: ## Run unit tests
@echo "\033[2m→ Running unit tests...\033[0m"
ifdef race
$(eval testunitargs += "-race")
endif
$(eval testunitargs += "-cover" "-coverprofile=tmp/unit.cov" "./...")
@mkdir -p tmp
@if which gotestsum > /dev/null 2>&1 ; then \
echo "gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml --" $(testunitargs); \
gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml -- $(testunitargs); \
else \
echo "go test -v" $(testunitargs); \
go test -v $(testunitargs); \
fi;
test: test-unit
test-integ: ## Run integration tests
@echo "\033[2m→ Running integration tests...\033[0m"
$(eval testintegtags += "integration")
ifdef multinode
$(eval testintegtags += "multinode")
endif
ifdef race
$(eval testintegargs += "-race")
endif
$(eval testintegargs += "-cover" "-coverprofile=tmp/integration-client.cov" "-tags='$(testintegtags)'" "-timeout=1h")
@mkdir -p tmp
@if which gotestsum > /dev/null 2>&1 ; then \
echo "gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml --" $(testintegargs); \
gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "."; \
gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./estransport" "./esapi" "./esutil"; \
else \
echo "go test -v" $(testintegargs) "."; \
go test -v $(testintegargs) "./estransport" "./esapi" "./esutil"; \
fi;
test-api: ## Run generated API integration tests
@mkdir -p tmp
ifdef race
$(eval testapiargs += "-race")
endif
$(eval testapiargs += "-cover" "-coverpkg=github.com/elastic/go-elasticsearch/v5/esapi" "-coverprofile=$(PWD)/tmp/integration-api.cov" "-tags='integration'" "-timeout=1h")
ifdef flavor
else
$(eval flavor='core')
endif
@echo "\033[2m→ Running API integration tests for [$(flavor)]...\033[0m"
ifeq ($(flavor), xpack)
@{ \
export ELASTICSEARCH_URL='https://elastic:elastic@localhost:9200' && \
if which gotestsum > /dev/null 2>&1 ; then \
cd esapi/test && \
gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \
gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \
gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \
else \
echo "go test -v" $(testapiargs); \
cd esapi/test && \
go test -v $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \
go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \
go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \
fi; \
}
else
$(eval testapiargs += $(PWD)/esapi/test/*_test.go)
@{ \
if which gotestsum > /dev/null 2>&1 ; then \
cd esapi/test && gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs); \
else \
echo "go test -v" $(testapiargs); \
cd esapi/test && go test -v $(testapiargs); \
fi; \
}
endif
test-bench: ## Run benchmarks
@echo "\033[2m→ Running benchmarks...\033[0m"
go test -run=none -bench=. -benchmem ./...
test-examples: ## Execute the _examples
@echo "\033[2m→ Testing the examples...\033[0m"
@{ \
set -e ; \
for f in _examples/*.go; do \
echo "\033[2m────────────────────────────────────────────────────────────────────────────────"; \
echo "\033[1m$$f\033[0m"; \
echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
(go run $$f && true) || \
( \
echo "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
echo "\033[31;1m ERROR\033[0m"; \
false; \
); \
done; \
\
for f in _examples/*/; do \
echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
echo "\033[1m$$f\033[0m"; \
echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
(cd $$f && make test && true) || \
( \
echo "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
echo "\033[31;1m ERROR\033[0m"; \
false; \
); \
done; \
echo "\033[32m────────────────────────────────────────────────────────────────────────────────\033[0m"; \
\
echo "\033[32;1mSUCCESS\033[0m"; \
}
test-coverage: ## Generate test coverage report
@echo "\033[2m→ Generating test coverage report...\033[0m"
@go tool cover -html=tmp/unit.cov -o tmp/coverage.html
@go tool cover -func=tmp/unit.cov | 'grep' -v 'esapi/api\.' | sed 's/github.com\/elastic\/go-elasticsearch\///g'
@echo "--------------------------------------------------------------------------------\nopen tmp/coverage.html\n"
##@ Development
lint: ## Run lint on the package
@echo "\033[2m→ Running lint...\033[0m"
go vet github.com/elastic/go-elasticsearch/...
go list github.com/elastic/go-elasticsearch/... | 'grep' -v internal | xargs golint -set_exit_status
apidiff: ## Display API incompabilities
@if ! command -v apidiff > /dev/null; then \
echo "\033[31;1mERROR: apidiff not installed\033[0m"; \
echo "go get -u github.com/go-modules-by-example/apidiff"; \
echo "\033[2m→ https://github.com/go-modules-by-example/index/blob/master/019_apidiff/README.md\033[0m\n"; \
false; \
fi;
@rm -rf tmp/apidiff-OLD tmp/apidiff-NEW
@git clone --quiet --local .git/ tmp/apidiff-OLD
@mkdir -p tmp/apidiff-NEW
@tar -c --exclude .git --exclude tmp --exclude cmd . | tar -x -C tmp/apidiff-NEW
@echo "\033[2m→ Running apidiff...\033[0m"
@echo "tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi"
@{ \
set -e ; \
output=$$(apidiff tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi); \
echo "\n$$output\n"; \
if echo $$output | grep -i -e 'incompatible' - > /dev/null 2>&1; then \
echo "\n\033[31;1mFAILURE\033[0m\n"; \
false; \
else \
echo "\033[32;1mSUCCESS\033[0m"; \
fi; \
}
backport: ## Backport one or more commits from master into version branches
ifeq ($(origin commits), undefined)
@echo "Missing commit(s), exiting..."
@exit 2
endif
ifndef branches
$(eval branches_list = '7.x' '6.x' '5.x')
else
$(eval branches_list = $(shell echo $(branches) | tr ',' ' ') )
endif
$(eval commits_list = $(shell echo $(commits) | tr ',' ' '))
@echo "\033[2m→ Backporting commits [$(commits)]\033[0m"
@{ \
set -e -o pipefail; \
for commit in $(commits_list); do \
git show --pretty='%h | %s' --no-patch $$commit; \
done; \
echo ""; \
for branch in $(branches_list); do \
echo "\033[2m→ $$branch\033[0m"; \
git checkout $$branch; \
for commit in $(commits_list); do \
git cherry-pick -x $$commit; \
done; \
git status --short --branch; \
echo ""; \
done; \
echo "\033[2m→ Push updates to Github:\033[0m"; \
for branch in $(branches_list); do \
echo "git push --verbose origin $$branch"; \
done; \
}
release: ## Release a new version to Github
ifndef version
@echo "Missing version argument, exiting..."
@exit 2
endif
ifeq ($(version), "")
@echo "Empty version argument, exiting..."
@exit 2
endif
@echo "\033[2m→ Creating version $(version)...\033[0m"
@{ \
cp internal/version/version.go internal/version/version.go.OLD && \
cat internal/version/version.go.OLD | sed -e 's/Client = ".*"/Client = "$(version)"/' > internal/version/version.go && \
rm internal/version/version.go.OLD && \
go vet internal/version/version.go && \
go fmt internal/version/version.go && \
git diff --color-words internal/version/version.go | tail -n 1; \
}
@{ \
echo "\033[2m→ Commit and create Git tag? (y/n): \033[0m\c"; \
read continue; \
if [[ $$continue == "y" ]]; then \
git add internal/version/version.go && \
git commit --no-status --quiet --message "Release $(version)" && \
git tag --annotate v$(version) --message 'Release $(version)'; \
echo "\033[2mPush `git show --pretty='%h (%s)' --no-patch HEAD` to Github:\033[0m\n"; \
echo "\033[1m git push origin v$(version)\033[0m\n"; \
else \
echo "Aborting..."; \
exit 1; \
fi; \
}
godoc: ## Display documentation for the package
@echo "\033[2m→ Generating documentation...\033[0m"
@echo "open http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/\n"
mkdir -p /tmp/tmpgoroot/doc
rm -rf /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch
mkdir -p /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch
tar -c --exclude='.git' --exclude='tmp' . | tar -x -C /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch
GOROOT=/tmp/tmpgoroot/ GOPATH=/tmp/tmpgopath/ godoc -http=localhost:6060 -play
cluster: ## Launch an Elasticsearch cluster with Docker
$(eval version ?= "elasticsearch:5.6.15")
ifeq ($(origin nodes), undefined)
$(eval nodes = 1)
endif
@echo "\033[2m→ Launching" $(nodes) "node(s) of" $(version) "...\033[0m"
ifeq ($(shell test $(nodes) && test $(nodes) -gt 1; echo $$?),0)
$(eval detached ?= "true")
else
$(eval detached ?= "false")
endif
@docker network inspect elasticsearch > /dev/null 2>&1 || docker network create elasticsearch;
@{ \
for n in `seq 1 $(nodes)`; do \
if [[ -z "$$port" ]]; then \
hostport=$$((9199+$$n)); \
else \
hostport=$$port; \
fi; \
docker run \
--name "es$$n" \
--network elasticsearch \
--env "node.name=es$$n" \
--env "cluster.name=go-elasticsearch" \
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--env "discovery.zen.ping.unicast.hosts=es1" \
--env "bootstrap.memory_lock=true" \
--env "node.attr.testattr=test" \
--env "path.repo=/tmp" \
--env "repositories.url.allowed_urls=http://snapshot.test*" \
--env "xpack.security.enabled=false" \
--env "xpack.monitoring.enabled=false" \
--env "xpack.ml.enabled=false" \
--env ES_JAVA_OPTS="-Xms1g -Xmx1g" \
--volume `echo $(version) | tr -C "[:alnum:]" '-'`-node-$$n-data:/usr/share/elasticsearch/data \
--publish $$hostport:9200 \
--ulimit nofile=65536:65536 \
--ulimit memlock=-1:-1 \
--detach=$(detached) \
--rm \
docker.elastic.co/elasticsearch/$(version); \
done \
}
ifdef detached
@{ \
echo "\033[2m→ Waiting for the cluster...\033[0m"; \
docker run --network elasticsearch --rm appropriate/curl --max-time 120 --retry 120 --retry-delay 1 --retry-connrefused --show-error --silent http://es1:9200; \
output="\033[2mCluster ready; to remove containers:"; \
output="$$output docker rm -f"; \
for n in `seq 1 $(nodes)`; do \
output="$$output es$$n"; \
done; \
echo "$$output\033[0m"; \
}
endif
cluster-update: ## Update the Docker image
$(eval version ?= "elasticsearch:5.6.15")
@echo "\033[2m→ Updating the Docker image...\033[0m"
@docker pull docker.elastic.co/elasticsearch/$(version);
cluster-clean: ## Remove unused Docker volumes and networks
@echo "\033[2m→ Cleaning up Docker assets...\033[0m"
docker volume prune --force
docker network prune --force
docker: ## Build the Docker image and run it
docker build --file Dockerfile --tag elastic/go-elasticsearch .
docker run -it --network elasticsearch --volume $(PWD)/tmp:/tmp:rw,delegated --rm elastic/go-elasticsearch
##@ Generator
gen-api: ## Generate the API package from the JSON specification
$(eval input ?= tmp/elasticsearch)
$(eval output ?= esapi)
ifdef debug
$(eval args += --debug)
endif
ifdef ELASTICSEARCH_VERSION
$(eval version = $(ELASTICSEARCH_VERSION))
else
$(eval version = $(shell cat "$(input)/buildSrc/version.properties" | grep 'elasticsearch' | cut -d '=' -f 2 | tr -d ' '))
endif
ifdef ELASTICSEARCH_BUILD_HASH
$(eval build_hash = $(ELASTICSEARCH_BUILD_HASH))
else
$(eval build_hash = $(shell git --git-dir='$(input)/.git' rev-parse --short HEAD))
endif
@echo "\033[2m→ Generating API package from specification ($(version):$(build_hash))...\033[0m"
@{ \
export ELASTICSEARCH_VERSION=$(version) && \
export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \
cd internal/cmd/generate && \
go run main.go apisource --input '$(PWD)/$(input)/rest-api-spec/src/main/resources/rest-api-spec/api/*.json' --output '$(PWD)/$(output)' $(args) && \
go run main.go apistruct --output '$(PWD)/$(output)'; \
}
gen-tests: ## Generate the API tests from the YAML specification
$(eval input ?= tmp/elasticsearch)
$(eval output ?= esapi/test)
ifdef debug
$(eval args += --debug)
endif
ifdef ELASTICSEARCH_VERSION
$(eval version = $(ELASTICSEARCH_VERSION))
else
$(eval version = $(shell cat "$(input)/buildSrc/version.properties" | grep 'elasticsearch' | cut -d '=' -f 2 | tr -d ' '))
endif
ifdef ELASTICSEARCH_BUILD_HASH
$(eval build_hash = $(ELASTICSEARCH_BUILD_HASH))
else
$(eval build_hash = $(shell git --git-dir='$(input)/.git' rev-parse --short HEAD))
endif
@echo "\033[2m→ Generating API tests from specification ($(version):$(build_hash))...\033[0m"
@{ \
export ELASTICSEARCH_VERSION=$(version) && \
export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \
rm -rf $(output)/*_test.go && \
rm -rf $(output)/xpack && \
cd internal/cmd/generate && \
go generate ./... && \
go run main.go apitests --input '$(PWD)/$(input)/rest-api-spec/src/main/resources/rest-api-spec/test/**/*.y*ml' --output '$(PWD)/$(output)' $(args); \
}
##@ Other
#------------------------------------------------------------------------------
help: ## Display help
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
#------------- <https://suva.sh/posts/well-documented-makefiles> --------------
.DEFAULT_GOAL := help
.PHONY: help apidiff backport cluster cluster-clean cluster-update coverage docker examples gen-api gen-tests godoc lint release test test-api test-bench test-integ test-unit

344
vendor/github.com/elastic/go-elasticsearch/v5/README.md generated vendored Normal file
View File

@@ -0,0 +1,344 @@
# go-elasticsearch
The official Go client for [Elasticsearch](https://www.elastic.co/products/elasticsearch).
[![GoDoc](https://godoc.org/github.com/elastic/go-elasticsearch?status.svg)](http://godoc.org/github.com/elastic/go-elasticsearch)
[![Travis-CI](https://travis-ci.org/elastic/go-elasticsearch.svg?branch=master)](https://travis-ci.org/elastic/go-elasticsearch)
[![Go Report Card](https://goreportcard.com/badge/github.com/elastic/go-elasticsearch)](https://goreportcard.com/report/github.com/elastic/go-elasticsearch)
[![codecov.io](https://codecov.io/github/elastic/go-elasticsearch/coverage.svg?branch=master)](https://codecov.io/gh/elastic/go-elasticsearch?branch=master)
## Compatibility
The client major versions correspond to the compatible Elasticsearch major versions: to connect to Elasticsearch `7.x`, use a [`7.x`](https://github.com/elastic/go-elasticsearch/tree/7.x) version of the client, to connect to Elasticsearch `6.x`, use a [`6.x`](https://github.com/elastic/go-elasticsearch/tree/6.x) version of the client.
When using Go modules, include the version in the import path, and specify either an explicit version or a branch:
require github.com/elastic/go-elasticsearch/v7 7.x
require github.com/elastic/go-elasticsearch/v7 7.0.0
It's possible to use multiple versions of the client in a single project:
// go.mod
github.com/elastic/go-elasticsearch/v6 6.x
github.com/elastic/go-elasticsearch/v7 7.x
// main.go
import (
elasticsearch6 "github.com/elastic/go-elasticsearch/v6"
elasticsearch7 "github.com/elastic/go-elasticsearch/v7"
)
// ...
es6, _ := elasticsearch6.NewDefaultClient()
es7, _ := elasticsearch7.NewDefaultClient()
The `master` branch of the client is compatible with the current `master` branch of Elasticsearch.
<!-- ----------------------------------------------------------------------------------------------- -->
## Installation
Add the package to your `go.mod` file:
require github.com/elastic/go-elasticsearch/v5 5.x
Or, clone the repository:
git clone --branch 5.x https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github.com/elastic/go-elasticsearch
A complete example:
```bash
mkdir my-elasticsearch-app && cd my-elasticsearch-app
cat > go.mod <<-END
module my-elasticsearch-app
require github.com/elastic/go-elasticsearch/v5 5.x
END
cat > main.go <<-END
package main
import (
"log"
"github.com/elastic/go-elasticsearch/v5"
)
func main() {
es, _ := elasticsearch.NewDefaultClient()
log.Println(elasticsearch.Version)
log.Println(es.Info())
}
END
go run main.go
```
<!-- ----------------------------------------------------------------------------------------------- -->
## Usage
The `elasticsearch` package ties together two separate packages for calling the Elasticsearch APIs and transferring data over HTTP: `esapi` and `estransport`, respectively.
Use the `elasticsearch.NewDefaultClient()` function to create the client with the default settings.
```golang
es, err := elasticsearch.NewDefaultClient()
if err != nil {
log.Fatalf("Error creating the client: %s", err)
}
res, err := es.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
log.Println(res)
// [200 OK] {
// "name" : "node-1",
// "cluster_name" : "go-elasticsearch"
// ...
```
When you export the `ELASTICSEARCH_URL` environment variable,
it will be used to set the cluster endpoint(s). Separate multiple adresses by a comma.
To set the cluster endpoint(s) programatically, pass them in the configuration object
to the `elasticsearch.NewClient()` function.
```golang
cfg := elasticsearch.Config{
Addresses: []string{
"http://localhost:9200",
"http://localhost:9201",
},
}
es, err := elasticsearch.NewClient(cfg)
// ...
```
To configure the HTTP settings, pass a [`http.Transport`](https://golang.org/pkg/net/http/#Transport)
object in the configuration object (the values are for illustrative purposes only).
```golang
cfg := elasticsearch.Config{
Transport: &http.Transport{
MaxIdleConnsPerHost: 10,
ResponseHeaderTimeout: time.Second,
DialContext: (&net.Dialer{Timeout: time.Second}).DialContext,
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS11,
// ...
},
},
}
es, err := elasticsearch.NewClient(cfg)
// ...
```
See the [`_examples/configuration.go`](_examples/configuration.go) and
[`_examples/customization.go`](_examples/customization.go) files for
more examples of configuration and customization of the client.
The following example demonstrates a more complex usage. It fetches the Elasticsearch version from the cluster, indexes a couple of documents concurrently, and prints the search results, using a lightweight wrapper around the response body.
```golang
// $ go run _examples/main.go
package main
import (
"bytes"
"context"
"encoding/json"
"log"
"strconv"
"strings"
"sync"
"github.com/elastic/go-elasticsearch/v5"
"github.com/elastic/go-elasticsearch/v5/esapi"
)
func main() {
log.SetFlags(0)
var (
r map[string]interface{}
wg sync.WaitGroup
)
// Initialize a client with the default settings.
//
// An `ELASTICSEARCH_URL` environment variable will be used when exported.
//
es, err := elasticsearch.NewDefaultClient()
if err != nil {
log.Fatalf("Error creating the client: %s", err)
}
// 1. Get cluster info
//
res, err := es.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
// Check response status
if res.IsError() {
log.Fatalf("Error: %s", res.String())
}
// Deserialize the response into a map.
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
// Print client and server version numbers.
log.Printf("Client: %s", elasticsearch.Version)
log.Printf("Server: %s", r["version"].(map[string]interface{})["number"])
log.Println(strings.Repeat("~", 37))
// 2. Index documents concurrently
//
for i, title := range []string{"Test One", "Test Two"} {
wg.Add(1)
go func(i int, title string) {
defer wg.Done()
// Build the request body.
var b strings.Builder
b.WriteString(`{"title" : "`)
b.WriteString(title)
b.WriteString(`"}`)
// Set up the request object.
req := esapi.IndexRequest{
Index: "test",
DocumentType: "test",
DocumentID: strconv.Itoa(i + 1),
Body: strings.NewReader(b.String()),
Refresh: "true",
}
// Perform the request with the client.
res, err := req.Do(context.Background(), es)
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
defer res.Body.Close()
if res.IsError() {
log.Printf("[%s] Error indexing document ID=%d", res.Status(), i+1)
} else {
// Deserialize the response into a map.
var r map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
log.Printf("Error parsing the response body: %s", err)
} else {
// Print the response status and indexed document version.
log.Printf("[%s] %s; version=%d", res.Status(), r["result"], int(r["_version"].(float64)))
}
}
}(i, title)
}
wg.Wait()
log.Println(strings.Repeat("-", 37))
// 3. Search for the indexed documents
//
// Build the request body.
var buf bytes.Buffer
query := map[string]interface{}{
"query": map[string]interface{}{
"match": map[string]interface{}{
"title": "test",
},
},
}
if err := json.NewEncoder(&buf).Encode(query); err != nil {
log.Fatalf("Error encoding query: %s", err)
}
// Perform the search request.
res, err = es.Search(
es.Search.WithContext(context.Background()),
es.Search.WithIndex("test"),
es.Search.WithBody(&buf),
es.Search.WithPretty(),
)
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
defer res.Body.Close()
if res.IsError() {
var e map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&e); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
} else {
// Print the response status and error information.
log.Fatalf("[%s] %s: %s",
res.Status(),
e["error"].(map[string]interface{})["type"],
e["error"].(map[string]interface{})["reason"],
)
}
}
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
// Print the response status, number of results, and request duration.
log.Printf(
"[%s] %d hits; took: %dms",
res.Status(),
int(r["hits"].(map[string]interface{})["total"].(float64)),
int(r["took"].(float64)),
)
// Print the ID and document source for each hit.
for _, hit := range r["hits"].(map[string]interface{})["hits"].([]interface{}) {
log.Printf(" * ID=%s, %s", hit.(map[string]interface{})["_id"], hit.(map[string]interface{})["_source"])
}
log.Println(strings.Repeat("=", 37))
}
// Client: 5.6.0-SNAPSHOT
// Server: 5.6.15
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// [201 Created] updated; version=1
// [201 Created] updated; version=1
// -------------------------------------
// [200 OK] 2 hits; took: 5ms
// * ID=1, map[title:Test One]
// * ID=2, map[title:Test Two]
// =====================================
```
As you see in the example above, the `esapi` package allows to call the Elasticsearch APIs in two distinct ways: either by creating a struct, such as `IndexRequest`, and calling its `Do()` method by passing it a context and the client, or by calling the `Search()` function on the client directly, using the option functions such as `WithIndex()`. See more information and examples in the
[package documentation](https://godoc.org/github.com/elastic/go-elasticsearch/esapi).
The `estransport` package handles the transfer of data to and from Elasticsearch. At the moment, the implementation is really minimal: it only round-robins across the configured cluster endpoints. In future, more features — retrying failed requests, ignoring certain status codes, auto-discovering nodes in the cluster, and so on — will be added.
<!-- ----------------------------------------------------------------------------------------------- -->
## Helpers
The `esutil` package provides convenience helpers for working with the client. At the moment, it provides the
`esutil.JSONReader()` helper function.
<!-- ----------------------------------------------------------------------------------------------- -->
## Examples
The **[`_examples`](./_examples)** folder contains a number of recipes and comprehensive examples to get you started with the client, including configuration and customization of the client, mocking the transport for unit tests, embedding the client in a custom type, building queries, performing requests, and parsing the responses.
<!-- ----------------------------------------------------------------------------------------------- -->
## License
(c) 2019 Elasticsearch. Licensed under the Apache License, Version 2.0.

45
vendor/github.com/elastic/go-elasticsearch/v5/doc.go generated vendored Normal file
View File

@@ -0,0 +1,45 @@
/*
Package elasticsearch provides a Go client for Elasticsearch.
Create the client with the NewDefaultClient function:
elasticsearch.NewDefaultClient()
The ELASTICSEARCH_URL environment variable is used instead of the default URL, when set.
Use a comma to separate multiple URLs.
To configure the client, pass a Config object to the NewClient function:
cfg := elasticsearch.Config{
Addresses: []string{
"http://localhost:9200",
"http://localhost:9201",
},
Username: "foo",
Password: "bar",
Transport: &http.Transport{
MaxIdleConnsPerHost: 10,
ResponseHeaderTimeout: time.Second,
DialContext: (&net.Dialer{Timeout: time.Second}).DialContext,
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS11,
},
},
}
elasticsearch.NewClient(cfg)
See the elasticsearch_integration_test.go file and the _examples folder for more information.
Call the Elasticsearch APIs by invoking the corresponding methods on the client:
res, err := es.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
log.Println(res)
See the github.com/elastic/go-elasticsearch/esapi package for more information and examples.
*/
package elasticsearch

View File

@@ -0,0 +1,129 @@
package elasticsearch
import (
"errors"
"fmt"
"net/http"
"net/url"
"os"
"strings"
"github.com/elastic/go-elasticsearch/v5/esapi"
"github.com/elastic/go-elasticsearch/v5/estransport"
"github.com/elastic/go-elasticsearch/v5/internal/version"
)
const (
defaultURL = "http://localhost:9200"
)
// Version returns the package version as a string.
//
const Version = version.Client
// Config represents the client configuration.
//
type Config struct {
Addresses []string // A list of Elasticsearch nodes to use.
Username string // Username for HTTP Basic Authentication.
Password string // Password for HTTP Basic Authentication.
Transport http.RoundTripper // The HTTP transport object.
Logger estransport.Logger // The logger object.
}
// Client represents the Elasticsearch client.
//
type Client struct {
*esapi.API // Embeds the API methods
Transport estransport.Interface
}
// NewDefaultClient creates a new client with default options.
//
// It will use http://localhost:9200 as the default address.
//
// It will use the ELASTICSEARCH_URL environment variable, if set,
// to configure the addresses; use a comma to separate multiple URLs.
//
func NewDefaultClient() (*Client, error) {
return NewClient(Config{})
}
// NewClient creates a new client with configuration from cfg.
//
// It will use http://localhost:9200 as the default address.
//
// It will use the ELASTICSEARCH_URL environment variable, if set,
// to configure the addresses; use a comma to separate multiple URLs.
//
// It's an error to set both cfg.Addresses and the ELASTICSEARCH_URL
// environment variable.
//
func NewClient(cfg Config) (*Client, error) {
envAddrs := addrsFromEnvironment()
if len(envAddrs) > 0 && len(cfg.Addresses) > 0 {
return nil, errors.New("cannot create client: both ELASTICSEARCH_URL and Addresses are set")
}
addrs := append(envAddrs, cfg.Addresses...)
urls, err := addrsToURLs(addrs)
if err != nil {
return nil, fmt.Errorf("cannot create client: %s", err)
}
if len(urls) == 0 {
u, _ := url.Parse(defaultURL) // errcheck exclude
urls = append(urls, u)
}
tp := estransport.New(estransport.Config{
URLs: urls,
Username: cfg.Username,
Password: cfg.Password,
Transport: cfg.Transport,
Logger: cfg.Logger,
})
return &Client{Transport: tp, API: esapi.New(tp)}, nil
}
// Perform delegates to Transport to execute a request and return a response.
//
func (c *Client) Perform(req *http.Request) (*http.Response, error) {
return c.Transport.Perform(req)
}
// addrsFromEnvironment returns a list of addresses by splitting
// the ELASTICSEARCH_URL environment variable with comma, or an empty list.
//
func addrsFromEnvironment() []string {
var addrs []string
if envURLs, ok := os.LookupEnv("ELASTICSEARCH_URL"); ok && envURLs != "" {
list := strings.Split(envURLs, ",")
for _, u := range list {
addrs = append(addrs, strings.TrimSpace(u))
}
}
return addrs
}
// addrsToURLs creates a list of url.URL structures from url list.
//
func addrsToURLs(addrs []string) ([]*url.URL, error) {
var urls []*url.URL
for _, addr := range addrs {
u, err := url.Parse(strings.TrimRight(addr, "/"))
if err != nil {
return nil, fmt.Errorf("cannot parse url: %v", err)
}
urls = append(urls, u)
}
return urls, nil
}

View File

@@ -0,0 +1,335 @@
// Code generated from specification version 5.6.15 (fe7575a32e2): DO NOT EDIT
package esapi
// API contains the Elasticsearch APIs
//
type API struct {
Cat *Cat
Cluster *Cluster
Indices *Indices
Ingest *Ingest
Nodes *Nodes
Remote *Remote
Snapshot *Snapshot
Tasks *Tasks
Bulk Bulk
ClearScroll ClearScroll
CountPercolate CountPercolate
Count Count
Create Create
DeleteByQuery DeleteByQuery
DeleteByQueryRethrottle DeleteByQueryRethrottle
Delete Delete
DeleteScript DeleteScript
DeleteTemplate DeleteTemplate
Exists Exists
ExistsSource ExistsSource
Explain Explain
FieldCaps FieldCaps
FieldStats FieldStats
Get Get
GetScript GetScript
GetSource GetSource
GetTemplate GetTemplate
Index Index
Info Info
Mget Mget
Mpercolate Mpercolate
Msearch Msearch
MsearchTemplate MsearchTemplate
Mtermvectors Mtermvectors
Percolate Percolate
Ping Ping
PutScript PutScript
PutTemplate PutTemplate
RankEval RankEval
Reindex Reindex
ReindexRethrottle ReindexRethrottle
RenderSearchTemplate RenderSearchTemplate
ScriptsPainlessExecute ScriptsPainlessExecute
Scroll Scroll
Search Search
SearchShards SearchShards
SearchTemplate SearchTemplate
Suggest Suggest
Termvectors Termvectors
UpdateByQuery UpdateByQuery
UpdateByQueryRethrottle UpdateByQueryRethrottle
Update Update
}
// Cat contains the Cat APIs
type Cat struct {
Aliases CatAliases
Allocation CatAllocation
Count CatCount
Fielddata CatFielddata
Health CatHealth
Help CatHelp
Indices CatIndices
Master CatMaster
Nodeattrs CatNodeattrs
Nodes CatNodes
PendingTasks CatPendingTasks
Plugins CatPlugins
Recovery CatRecovery
Repositories CatRepositories
Segments CatSegments
Shards CatShards
Snapshots CatSnapshots
Tasks CatTasks
Templates CatTemplates
ThreadPool CatThreadPool
}
// Cluster contains the Cluster APIs
type Cluster struct {
AllocationExplain ClusterAllocationExplain
GetSettings ClusterGetSettings
Health ClusterHealth
PendingTasks ClusterPendingTasks
PutSettings ClusterPutSettings
RemoteInfo ClusterRemoteInfo
Reroute ClusterReroute
State ClusterState
Stats ClusterStats
}
// Indices contains the Indices APIs
type Indices struct {
Analyze IndicesAnalyze
ClearCache IndicesClearCache
Close IndicesClose
Create IndicesCreate
DeleteAlias IndicesDeleteAlias
Delete IndicesDelete
DeleteTemplate IndicesDeleteTemplate
ExistsAlias IndicesExistsAlias
ExistsDocumentType IndicesExistsDocumentType
Exists IndicesExists
ExistsTemplate IndicesExistsTemplate
Flush IndicesFlush
FlushSynced IndicesFlushSynced
Forcemerge IndicesForcemerge
GetAlias IndicesGetAlias
GetFieldMapping IndicesGetFieldMapping
GetMapping IndicesGetMapping
Get IndicesGet
GetSettings IndicesGetSettings
GetTemplate IndicesGetTemplate
GetUpgrade IndicesGetUpgrade
Open IndicesOpen
PutAlias IndicesPutAlias
PutMapping IndicesPutMapping
PutSettings IndicesPutSettings
PutTemplate IndicesPutTemplate
Recovery IndicesRecovery
Refresh IndicesRefresh
Rollover IndicesRollover
Segments IndicesSegments
ShardStores IndicesShardStores
Shrink IndicesShrink
Split IndicesSplit
Stats IndicesStats
UpdateAliases IndicesUpdateAliases
Upgrade IndicesUpgrade
ValidateQuery IndicesValidateQuery
}
// Ingest contains the Ingest APIs
type Ingest struct {
DeletePipeline IngestDeletePipeline
GetPipeline IngestGetPipeline
ProcessorGrok IngestProcessorGrok
PutPipeline IngestPutPipeline
Simulate IngestSimulate
}
// Nodes contains the Nodes APIs
type Nodes struct {
HotThreads NodesHotThreads
Info NodesInfo
ReloadSecureSettings NodesReloadSecureSettings
Stats NodesStats
Usage NodesUsage
}
// Remote contains the Remote APIs
type Remote struct {
}
// Snapshot contains the Snapshot APIs
type Snapshot struct {
CreateRepository SnapshotCreateRepository
Create SnapshotCreate
DeleteRepository SnapshotDeleteRepository
Delete SnapshotDelete
GetRepository SnapshotGetRepository
Get SnapshotGet
Restore SnapshotRestore
Status SnapshotStatus
VerifyRepository SnapshotVerifyRepository
}
// Tasks contains the Tasks APIs
type Tasks struct {
Cancel TasksCancel
Get TasksGet
List TasksList
}
// New creates new API
//
func New(t Transport) *API {
return &API{
Bulk: newBulkFunc(t),
ClearScroll: newClearScrollFunc(t),
CountPercolate: newCountPercolateFunc(t),
Count: newCountFunc(t),
Create: newCreateFunc(t),
DeleteByQuery: newDeleteByQueryFunc(t),
DeleteByQueryRethrottle: newDeleteByQueryRethrottleFunc(t),
Delete: newDeleteFunc(t),
DeleteScript: newDeleteScriptFunc(t),
DeleteTemplate: newDeleteTemplateFunc(t),
Exists: newExistsFunc(t),
ExistsSource: newExistsSourceFunc(t),
Explain: newExplainFunc(t),
FieldCaps: newFieldCapsFunc(t),
FieldStats: newFieldStatsFunc(t),
Get: newGetFunc(t),
GetScript: newGetScriptFunc(t),
GetSource: newGetSourceFunc(t),
GetTemplate: newGetTemplateFunc(t),
Index: newIndexFunc(t),
Info: newInfoFunc(t),
Mget: newMgetFunc(t),
Mpercolate: newMpercolateFunc(t),
Msearch: newMsearchFunc(t),
MsearchTemplate: newMsearchTemplateFunc(t),
Mtermvectors: newMtermvectorsFunc(t),
Percolate: newPercolateFunc(t),
Ping: newPingFunc(t),
PutScript: newPutScriptFunc(t),
PutTemplate: newPutTemplateFunc(t),
RankEval: newRankEvalFunc(t),
Reindex: newReindexFunc(t),
ReindexRethrottle: newReindexRethrottleFunc(t),
RenderSearchTemplate: newRenderSearchTemplateFunc(t),
ScriptsPainlessExecute: newScriptsPainlessExecuteFunc(t),
Scroll: newScrollFunc(t),
Search: newSearchFunc(t),
SearchShards: newSearchShardsFunc(t),
SearchTemplate: newSearchTemplateFunc(t),
Suggest: newSuggestFunc(t),
Termvectors: newTermvectorsFunc(t),
UpdateByQuery: newUpdateByQueryFunc(t),
UpdateByQueryRethrottle: newUpdateByQueryRethrottleFunc(t),
Update: newUpdateFunc(t),
Cat: &Cat{
Aliases: newCatAliasesFunc(t),
Allocation: newCatAllocationFunc(t),
Count: newCatCountFunc(t),
Fielddata: newCatFielddataFunc(t),
Health: newCatHealthFunc(t),
Help: newCatHelpFunc(t),
Indices: newCatIndicesFunc(t),
Master: newCatMasterFunc(t),
Nodeattrs: newCatNodeattrsFunc(t),
Nodes: newCatNodesFunc(t),
PendingTasks: newCatPendingTasksFunc(t),
Plugins: newCatPluginsFunc(t),
Recovery: newCatRecoveryFunc(t),
Repositories: newCatRepositoriesFunc(t),
Segments: newCatSegmentsFunc(t),
Shards: newCatShardsFunc(t),
Snapshots: newCatSnapshotsFunc(t),
Tasks: newCatTasksFunc(t),
Templates: newCatTemplatesFunc(t),
ThreadPool: newCatThreadPoolFunc(t),
},
Cluster: &Cluster{
AllocationExplain: newClusterAllocationExplainFunc(t),
GetSettings: newClusterGetSettingsFunc(t),
Health: newClusterHealthFunc(t),
PendingTasks: newClusterPendingTasksFunc(t),
PutSettings: newClusterPutSettingsFunc(t),
RemoteInfo: newClusterRemoteInfoFunc(t),
Reroute: newClusterRerouteFunc(t),
State: newClusterStateFunc(t),
Stats: newClusterStatsFunc(t),
},
Indices: &Indices{
Analyze: newIndicesAnalyzeFunc(t),
ClearCache: newIndicesClearCacheFunc(t),
Close: newIndicesCloseFunc(t),
Create: newIndicesCreateFunc(t),
DeleteAlias: newIndicesDeleteAliasFunc(t),
Delete: newIndicesDeleteFunc(t),
DeleteTemplate: newIndicesDeleteTemplateFunc(t),
ExistsAlias: newIndicesExistsAliasFunc(t),
ExistsDocumentType: newIndicesExistsDocumentTypeFunc(t),
Exists: newIndicesExistsFunc(t),
ExistsTemplate: newIndicesExistsTemplateFunc(t),
Flush: newIndicesFlushFunc(t),
FlushSynced: newIndicesFlushSyncedFunc(t),
Forcemerge: newIndicesForcemergeFunc(t),
GetAlias: newIndicesGetAliasFunc(t),
GetFieldMapping: newIndicesGetFieldMappingFunc(t),
GetMapping: newIndicesGetMappingFunc(t),
Get: newIndicesGetFunc(t),
GetSettings: newIndicesGetSettingsFunc(t),
GetTemplate: newIndicesGetTemplateFunc(t),
GetUpgrade: newIndicesGetUpgradeFunc(t),
Open: newIndicesOpenFunc(t),
PutAlias: newIndicesPutAliasFunc(t),
PutMapping: newIndicesPutMappingFunc(t),
PutSettings: newIndicesPutSettingsFunc(t),
PutTemplate: newIndicesPutTemplateFunc(t),
Recovery: newIndicesRecoveryFunc(t),
Refresh: newIndicesRefreshFunc(t),
Rollover: newIndicesRolloverFunc(t),
Segments: newIndicesSegmentsFunc(t),
ShardStores: newIndicesShardStoresFunc(t),
Shrink: newIndicesShrinkFunc(t),
Split: newIndicesSplitFunc(t),
Stats: newIndicesStatsFunc(t),
UpdateAliases: newIndicesUpdateAliasesFunc(t),
Upgrade: newIndicesUpgradeFunc(t),
ValidateQuery: newIndicesValidateQueryFunc(t),
},
Ingest: &Ingest{
DeletePipeline: newIngestDeletePipelineFunc(t),
GetPipeline: newIngestGetPipelineFunc(t),
ProcessorGrok: newIngestProcessorGrokFunc(t),
PutPipeline: newIngestPutPipelineFunc(t),
Simulate: newIngestSimulateFunc(t),
},
Nodes: &Nodes{
HotThreads: newNodesHotThreadsFunc(t),
Info: newNodesInfoFunc(t),
ReloadSecureSettings: newNodesReloadSecureSettingsFunc(t),
Stats: newNodesStatsFunc(t),
Usage: newNodesUsageFunc(t),
},
Remote: &Remote{},
Snapshot: &Snapshot{
CreateRepository: newSnapshotCreateRepositoryFunc(t),
Create: newSnapshotCreateFunc(t),
DeleteRepository: newSnapshotDeleteRepositoryFunc(t),
Delete: newSnapshotDeleteFunc(t),
GetRepository: newSnapshotGetRepositoryFunc(t),
Get: newSnapshotGetFunc(t),
Restore: newSnapshotRestoreFunc(t),
Status: newSnapshotStatusFunc(t),
VerifyRepository: newSnapshotVerifyRepositoryFunc(t),
},
Tasks: &Tasks{
Cancel: newTasksCancelFunc(t),
Get: newTasksGetFunc(t),
List: newTasksListFunc(t),
},
}
}

View File

@@ -0,0 +1,323 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strings"
"time"
)
func newBulkFunc(t Transport) Bulk {
return func(body io.Reader, o ...func(*BulkRequest)) (*Response, error) {
var r = BulkRequest{Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Bulk allows to perform multiple index/update/delete operations in a single request.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-bulk.html.
//
type Bulk func(body io.Reader, o ...func(*BulkRequest)) (*Response, error)
// BulkRequest configures the Bulk API request.
//
type BulkRequest struct {
Index string
DocumentType string
Body io.Reader
Fields []string
Pipeline string
Refresh string
Routing string
Source []string
SourceExclude []string
SourceInclude []string
Timeout time.Duration
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r BulkRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len("_bulk"))
if r.Index != "" {
path.WriteString("/")
path.WriteString(r.Index)
}
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString("_bulk")
params = make(map[string]string)
if len(r.Fields) > 0 {
params["fields"] = strings.Join(r.Fields, ",")
}
if r.Pipeline != "" {
params["pipeline"] = r.Pipeline
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.DocumentType != "" {
params["type"] = r.DocumentType
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Bulk) WithContext(v context.Context) func(*BulkRequest) {
return func(r *BulkRequest) {
r.ctx = v
}
}
// WithIndex - default index for items which don't provide one.
//
func (f Bulk) WithIndex(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Index = v
}
}
// WithDocumentType - default document type for items which don't provide one.
//
func (f Bulk) WithDocumentType(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.DocumentType = v
}
}
// WithFields - default comma-separated list of fields to return in the response for updates, can be overridden on each sub-request.
//
func (f Bulk) WithFields(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Fields = v
}
}
// WithPipeline - the pipeline ID to preprocess incoming documents with.
//
func (f Bulk) WithPipeline(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Pipeline = v
}
}
// WithRefresh - if `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes..
//
func (f Bulk) WithRefresh(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Refresh = v
}
}
// WithRouting - specific routing value.
//
func (f Bulk) WithRouting(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or default list of fields to return, can be overridden on each sub-request.
//
func (f Bulk) WithSource(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Source = v
}
}
// WithSourceExclude - default list of fields to exclude from the returned _source field, can be overridden on each sub-request.
//
func (f Bulk) WithSourceExclude(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - default list of fields to extract and return from the _source field, can be overridden on each sub-request.
//
func (f Bulk) WithSourceInclude(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.SourceInclude = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f Bulk) WithTimeout(v time.Duration) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Timeout = v
}
}
// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the bulk operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1).
//
func (f Bulk) WithWaitForActiveShards(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Bulk) WithPretty() func(*BulkRequest) {
return func(r *BulkRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Bulk) WithHuman() func(*BulkRequest) {
return func(r *BulkRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Bulk) WithErrorTrace() func(*BulkRequest) {
return func(r *BulkRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Bulk) WithFilterPath(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Bulk) WithHeader(h map[string]string) func(*BulkRequest) {
return func(r *BulkRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,276 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatAliasesFunc(t Transport) CatAliases {
return func(o ...func(*CatAliasesRequest)) (*Response, error) {
var r = CatAliasesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatAliases shows information about currently configured aliases to indices including filter and routing infos.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-alias.html.
//
type CatAliases func(o ...func(*CatAliasesRequest)) (*Response, error)
// CatAliasesRequest configures the Cat Aliases API request.
//
type CatAliasesRequest struct {
Name []string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatAliasesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("aliases") + 1 + len(strings.Join(r.Name, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("aliases")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatAliases) WithContext(v context.Context) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.ctx = v
}
}
// WithName - a list of alias names to return.
//
func (f CatAliases) WithName(v ...string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Name = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatAliases) WithFormat(v string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatAliases) WithH(v ...string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatAliases) WithHelp(v bool) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatAliases) WithLocal(v bool) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatAliases) WithMasterTimeout(v time.Duration) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatAliases) WithS(v ...string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatAliases) WithV(v bool) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatAliases) WithPretty() func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatAliases) WithHuman() func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatAliases) WithErrorTrace() func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatAliases) WithFilterPath(v ...string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatAliases) WithHeader(h map[string]string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,289 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatAllocationFunc(t Transport) CatAllocation {
return func(o ...func(*CatAllocationRequest)) (*Response, error) {
var r = CatAllocationRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatAllocation provides a snapshot of how many shards are allocated to each data node and how much disk space they are using.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-allocation.html.
//
type CatAllocation func(o ...func(*CatAllocationRequest)) (*Response, error)
// CatAllocationRequest configures the Cat Allocation API request.
//
type CatAllocationRequest struct {
NodeID []string
Bytes string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatAllocationRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("allocation") + 1 + len(strings.Join(r.NodeID, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("allocation")
if len(r.NodeID) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.NodeID, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatAllocation) WithContext(v context.Context) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.ctx = v
}
}
// WithNodeID - a list of node ids or names to limit the returned information.
//
func (f CatAllocation) WithNodeID(v ...string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.NodeID = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatAllocation) WithBytes(v string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatAllocation) WithFormat(v string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatAllocation) WithH(v ...string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatAllocation) WithHelp(v bool) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatAllocation) WithLocal(v bool) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatAllocation) WithMasterTimeout(v time.Duration) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatAllocation) WithS(v ...string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatAllocation) WithV(v bool) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatAllocation) WithPretty() func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatAllocation) WithHuman() func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatAllocation) WithErrorTrace() func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatAllocation) WithFilterPath(v ...string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatAllocation) WithHeader(h map[string]string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,276 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatCountFunc(t Transport) CatCount {
return func(o ...func(*CatCountRequest)) (*Response, error) {
var r = CatCountRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatCount provides quick access to the document count of the entire cluster, or individual indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-count.html.
//
type CatCount func(o ...func(*CatCountRequest)) (*Response, error)
// CatCountRequest configures the Cat Count API request.
//
type CatCountRequest struct {
Index []string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatCountRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("count") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("count")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatCount) WithContext(v context.Context) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to limit the returned information.
//
func (f CatCount) WithIndex(v ...string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Index = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatCount) WithFormat(v string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatCount) WithH(v ...string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatCount) WithHelp(v bool) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatCount) WithLocal(v bool) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatCount) WithMasterTimeout(v time.Duration) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatCount) WithS(v ...string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatCount) WithV(v bool) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatCount) WithPretty() func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatCount) WithHuman() func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatCount) WithErrorTrace() func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatCount) WithFilterPath(v ...string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatCount) WithHeader(h map[string]string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,293 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatFielddataFunc(t Transport) CatFielddata {
return func(o ...func(*CatFielddataRequest)) (*Response, error) {
var r = CatFielddataRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatFielddata shows how much heap memory is currently being used by fielddata on every data node in the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-fielddata.html.
//
type CatFielddata func(o ...func(*CatFielddataRequest)) (*Response, error)
// CatFielddataRequest configures the Cat Fielddata API request.
//
type CatFielddataRequest struct {
Fields []string
Bytes string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatFielddataRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("fielddata") + 1 + len(strings.Join(r.Fields, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("fielddata")
if len(r.Fields) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Fields, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if len(r.Fields) > 0 {
params["fields"] = strings.Join(r.Fields, ",")
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatFielddata) WithContext(v context.Context) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.ctx = v
}
}
// WithFields - a list of fields to return the fielddata size.
//
func (f CatFielddata) WithFields(v ...string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Fields = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatFielddata) WithBytes(v string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatFielddata) WithFormat(v string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatFielddata) WithH(v ...string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatFielddata) WithHelp(v bool) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatFielddata) WithLocal(v bool) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatFielddata) WithMasterTimeout(v time.Duration) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatFielddata) WithS(v ...string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatFielddata) WithV(v bool) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatFielddata) WithPretty() func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatFielddata) WithHuman() func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatFielddata) WithErrorTrace() func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatFielddata) WithFilterPath(v ...string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatFielddata) WithHeader(h map[string]string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,272 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatHealthFunc(t Transport) CatHealth {
return func(o ...func(*CatHealthRequest)) (*Response, error) {
var r = CatHealthRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatHealth returns a concise representation of the cluster health.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-health.html.
//
type CatHealth func(o ...func(*CatHealthRequest)) (*Response, error)
// CatHealthRequest configures the Cat Health API request.
//
type CatHealthRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
Ts *bool
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatHealthRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/health"))
path.WriteString("/_cat/health")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Ts != nil {
params["ts"] = strconv.FormatBool(*r.Ts)
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatHealth) WithContext(v context.Context) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatHealth) WithFormat(v string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatHealth) WithH(v ...string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatHealth) WithHelp(v bool) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatHealth) WithLocal(v bool) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatHealth) WithMasterTimeout(v time.Duration) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatHealth) WithS(v ...string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.S = v
}
}
// WithTs - set to false to disable timestamping.
//
func (f CatHealth) WithTs(v bool) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Ts = &v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatHealth) WithV(v bool) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatHealth) WithPretty() func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatHealth) WithHuman() func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatHealth) WithErrorTrace() func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatHealth) WithFilterPath(v ...string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatHealth) WithHeader(h map[string]string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,193 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newCatHelpFunc(t Transport) CatHelp {
return func(o ...func(*CatHelpRequest)) (*Response, error) {
var r = CatHelpRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatHelp returns help for the Cat APIs.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat.html.
//
type CatHelp func(o ...func(*CatHelpRequest)) (*Response, error)
// CatHelpRequest configures the Cat Help API request.
//
type CatHelpRequest struct {
Help *bool
S []string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatHelpRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat"))
path.WriteString("/_cat")
params = make(map[string]string)
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatHelp) WithContext(v context.Context) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.ctx = v
}
}
// WithHelp - return help information.
//
func (f CatHelp) WithHelp(v bool) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.Help = &v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatHelp) WithS(v ...string) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.S = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatHelp) WithPretty() func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatHelp) WithHuman() func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatHelp) WithErrorTrace() func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatHelp) WithFilterPath(v ...string) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatHelp) WithHeader(h map[string]string) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,315 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatIndicesFunc(t Transport) CatIndices {
return func(o ...func(*CatIndicesRequest)) (*Response, error) {
var r = CatIndicesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatIndices returns information about indices: number of primaries and replicas, document counts, disk size, ...
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-indices.html.
//
type CatIndices func(o ...func(*CatIndicesRequest)) (*Response, error)
// CatIndicesRequest configures the Cat Indices API request.
//
type CatIndicesRequest struct {
Index []string
Bytes string
Format string
H []string
Health string
Help *bool
Local *bool
MasterTimeout time.Duration
Pri *bool
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatIndicesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("indices") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("indices")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Health != "" {
params["health"] = r.Health
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Pri != nil {
params["pri"] = strconv.FormatBool(*r.Pri)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatIndices) WithContext(v context.Context) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to limit the returned information.
//
func (f CatIndices) WithIndex(v ...string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Index = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatIndices) WithBytes(v string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatIndices) WithFormat(v string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatIndices) WithH(v ...string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.H = v
}
}
// WithHealth - a health status ("green", "yellow", or "red" to filter only indices matching the specified health status.
//
func (f CatIndices) WithHealth(v string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Health = v
}
}
// WithHelp - return help information.
//
func (f CatIndices) WithHelp(v bool) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatIndices) WithLocal(v bool) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatIndices) WithMasterTimeout(v time.Duration) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.MasterTimeout = v
}
}
// WithPri - set to true to return stats only for primary shards.
//
func (f CatIndices) WithPri(v bool) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Pri = &v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatIndices) WithS(v ...string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatIndices) WithV(v bool) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatIndices) WithPretty() func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatIndices) WithHuman() func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatIndices) WithErrorTrace() func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatIndices) WithFilterPath(v ...string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatIndices) WithHeader(h map[string]string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,259 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatMasterFunc(t Transport) CatMaster {
return func(o ...func(*CatMasterRequest)) (*Response, error) {
var r = CatMasterRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatMaster returns information about the master node.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-master.html.
//
type CatMaster func(o ...func(*CatMasterRequest)) (*Response, error)
// CatMasterRequest configures the Cat Master API request.
//
type CatMasterRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatMasterRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/master"))
path.WriteString("/_cat/master")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatMaster) WithContext(v context.Context) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatMaster) WithFormat(v string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatMaster) WithH(v ...string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatMaster) WithHelp(v bool) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatMaster) WithLocal(v bool) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatMaster) WithMasterTimeout(v time.Duration) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatMaster) WithS(v ...string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatMaster) WithV(v bool) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatMaster) WithPretty() func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatMaster) WithHuman() func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatMaster) WithErrorTrace() func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatMaster) WithFilterPath(v ...string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatMaster) WithHeader(h map[string]string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,259 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatNodeattrsFunc(t Transport) CatNodeattrs {
return func(o ...func(*CatNodeattrsRequest)) (*Response, error) {
var r = CatNodeattrsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatNodeattrs returns information about custom node attributes.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-nodeattrs.html.
//
type CatNodeattrs func(o ...func(*CatNodeattrsRequest)) (*Response, error)
// CatNodeattrsRequest configures the Cat Nodeattrs API request.
//
type CatNodeattrsRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatNodeattrsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/nodeattrs"))
path.WriteString("/_cat/nodeattrs")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatNodeattrs) WithContext(v context.Context) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatNodeattrs) WithFormat(v string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatNodeattrs) WithH(v ...string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatNodeattrs) WithHelp(v bool) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatNodeattrs) WithLocal(v bool) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatNodeattrs) WithMasterTimeout(v time.Duration) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatNodeattrs) WithS(v ...string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatNodeattrs) WithV(v bool) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatNodeattrs) WithPretty() func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatNodeattrs) WithHuman() func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatNodeattrs) WithErrorTrace() func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatNodeattrs) WithFilterPath(v ...string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatNodeattrs) WithHeader(h map[string]string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,272 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatNodesFunc(t Transport) CatNodes {
return func(o ...func(*CatNodesRequest)) (*Response, error) {
var r = CatNodesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatNodes returns basic statistics about performance of cluster nodes.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-nodes.html.
//
type CatNodes func(o ...func(*CatNodesRequest)) (*Response, error)
// CatNodesRequest configures the Cat Nodes API request.
//
type CatNodesRequest struct {
Format string
FullID *bool
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatNodesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/nodes"))
path.WriteString("/_cat/nodes")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if r.FullID != nil {
params["full_id"] = strconv.FormatBool(*r.FullID)
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatNodes) WithContext(v context.Context) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatNodes) WithFormat(v string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Format = v
}
}
// WithFullID - return the full node ID instead of the shortened version (default: false).
//
func (f CatNodes) WithFullID(v bool) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.FullID = &v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatNodes) WithH(v ...string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatNodes) WithHelp(v bool) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatNodes) WithLocal(v bool) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatNodes) WithMasterTimeout(v time.Duration) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatNodes) WithS(v ...string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatNodes) WithV(v bool) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatNodes) WithPretty() func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatNodes) WithHuman() func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatNodes) WithErrorTrace() func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatNodes) WithFilterPath(v ...string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatNodes) WithHeader(h map[string]string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,259 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatPendingTasksFunc(t Transport) CatPendingTasks {
return func(o ...func(*CatPendingTasksRequest)) (*Response, error) {
var r = CatPendingTasksRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatPendingTasks returns a concise representation of the cluster pending tasks.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-pending-tasks.html.
//
type CatPendingTasks func(o ...func(*CatPendingTasksRequest)) (*Response, error)
// CatPendingTasksRequest configures the Cat Pending Tasks API request.
//
type CatPendingTasksRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatPendingTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/pending_tasks"))
path.WriteString("/_cat/pending_tasks")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatPendingTasks) WithContext(v context.Context) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatPendingTasks) WithFormat(v string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatPendingTasks) WithH(v ...string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatPendingTasks) WithHelp(v bool) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatPendingTasks) WithLocal(v bool) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatPendingTasks) WithMasterTimeout(v time.Duration) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatPendingTasks) WithS(v ...string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatPendingTasks) WithV(v bool) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatPendingTasks) WithPretty() func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatPendingTasks) WithHuman() func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatPendingTasks) WithErrorTrace() func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatPendingTasks) WithFilterPath(v ...string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatPendingTasks) WithHeader(h map[string]string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,259 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatPluginsFunc(t Transport) CatPlugins {
return func(o ...func(*CatPluginsRequest)) (*Response, error) {
var r = CatPluginsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatPlugins returns information about installed plugins across nodes node.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-plugins.html.
//
type CatPlugins func(o ...func(*CatPluginsRequest)) (*Response, error)
// CatPluginsRequest configures the Cat Plugins API request.
//
type CatPluginsRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatPluginsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/plugins"))
path.WriteString("/_cat/plugins")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatPlugins) WithContext(v context.Context) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatPlugins) WithFormat(v string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatPlugins) WithH(v ...string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatPlugins) WithHelp(v bool) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatPlugins) WithLocal(v bool) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatPlugins) WithMasterTimeout(v time.Duration) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatPlugins) WithS(v ...string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatPlugins) WithV(v bool) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatPlugins) WithPretty() func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatPlugins) WithHuman() func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatPlugins) WithErrorTrace() func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatPlugins) WithFilterPath(v ...string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatPlugins) WithHeader(h map[string]string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,276 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatRecoveryFunc(t Transport) CatRecovery {
return func(o ...func(*CatRecoveryRequest)) (*Response, error) {
var r = CatRecoveryRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatRecovery returns information about index shard recoveries, both on-going completed.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-recovery.html.
//
type CatRecovery func(o ...func(*CatRecoveryRequest)) (*Response, error)
// CatRecoveryRequest configures the Cat Recovery API request.
//
type CatRecoveryRequest struct {
Index []string
Bytes string
Format string
H []string
Help *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatRecoveryRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("recovery") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("recovery")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatRecovery) WithContext(v context.Context) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to limit the returned information.
//
func (f CatRecovery) WithIndex(v ...string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Index = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatRecovery) WithBytes(v string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatRecovery) WithFormat(v string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatRecovery) WithH(v ...string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatRecovery) WithHelp(v bool) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Help = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatRecovery) WithMasterTimeout(v time.Duration) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatRecovery) WithS(v ...string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatRecovery) WithV(v bool) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatRecovery) WithPretty() func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatRecovery) WithHuman() func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatRecovery) WithErrorTrace() func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatRecovery) WithFilterPath(v ...string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatRecovery) WithHeader(h map[string]string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,259 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatRepositoriesFunc(t Transport) CatRepositories {
return func(o ...func(*CatRepositoriesRequest)) (*Response, error) {
var r = CatRepositoriesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatRepositories returns information about snapshot repositories registered in the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-repositories.html.
//
type CatRepositories func(o ...func(*CatRepositoriesRequest)) (*Response, error)
// CatRepositoriesRequest configures the Cat Repositories API request.
//
type CatRepositoriesRequest struct {
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatRepositoriesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/repositories"))
path.WriteString("/_cat/repositories")
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatRepositories) WithContext(v context.Context) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatRepositories) WithFormat(v string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatRepositories) WithH(v ...string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatRepositories) WithHelp(v bool) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node.
//
func (f CatRepositories) WithLocal(v bool) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatRepositories) WithMasterTimeout(v time.Duration) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatRepositories) WithS(v ...string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatRepositories) WithV(v bool) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatRepositories) WithPretty() func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatRepositories) WithHuman() func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatRepositories) WithErrorTrace() func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatRepositories) WithFilterPath(v ...string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatRepositories) WithHeader(h map[string]string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,262 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newCatSegmentsFunc(t Transport) CatSegments {
return func(o ...func(*CatSegmentsRequest)) (*Response, error) {
var r = CatSegmentsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatSegments provides low-level information about the segments in the shards of an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-segments.html.
//
type CatSegments func(o ...func(*CatSegmentsRequest)) (*Response, error)
// CatSegmentsRequest configures the Cat Segments API request.
//
type CatSegmentsRequest struct {
Index []string
Bytes string
Format string
H []string
Help *bool
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatSegmentsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("segments") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("segments")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatSegments) WithContext(v context.Context) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to limit the returned information.
//
func (f CatSegments) WithIndex(v ...string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Index = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatSegments) WithBytes(v string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatSegments) WithFormat(v string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatSegments) WithH(v ...string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatSegments) WithHelp(v bool) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Help = &v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatSegments) WithS(v ...string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatSegments) WithV(v bool) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatSegments) WithPretty() func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatSegments) WithHuman() func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatSegments) WithErrorTrace() func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatSegments) WithFilterPath(v ...string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatSegments) WithHeader(h map[string]string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,289 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatShardsFunc(t Transport) CatShards {
return func(o ...func(*CatShardsRequest)) (*Response, error) {
var r = CatShardsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatShards provides a detailed view of shard allocation on nodes.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-shards.html.
//
type CatShards func(o ...func(*CatShardsRequest)) (*Response, error)
// CatShardsRequest configures the Cat Shards API request.
//
type CatShardsRequest struct {
Index []string
Bytes string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatShardsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("shards") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("shards")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatShards) WithContext(v context.Context) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to limit the returned information.
//
func (f CatShards) WithIndex(v ...string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Index = v
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatShards) WithBytes(v string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Bytes = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatShards) WithFormat(v string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatShards) WithH(v ...string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatShards) WithHelp(v bool) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatShards) WithLocal(v bool) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatShards) WithMasterTimeout(v time.Duration) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatShards) WithS(v ...string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatShards) WithV(v bool) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatShards) WithPretty() func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatShards) WithHuman() func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatShards) WithErrorTrace() func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatShards) WithFilterPath(v ...string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatShards) WithHeader(h map[string]string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,266 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatSnapshotsFunc(t Transport) CatSnapshots {
return func(repository []string, o ...func(*CatSnapshotsRequest)) (*Response, error) {
var r = CatSnapshotsRequest{Repository: repository}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatSnapshots returns all snapshots in a specific repository.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-snapshots.html.
//
type CatSnapshots func(repository []string, o ...func(*CatSnapshotsRequest)) (*Response, error)
// CatSnapshotsRequest configures the Cat Snapshots API request.
//
type CatSnapshotsRequest struct {
Repository []string
Format string
H []string
Help *bool
IgnoreUnavailable *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatSnapshotsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("snapshots") + 1 + len(strings.Join(r.Repository, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("snapshots")
path.WriteString("/")
path.WriteString(strings.Join(r.Repository, ","))
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatSnapshots) WithContext(v context.Context) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.ctx = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatSnapshots) WithFormat(v string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatSnapshots) WithH(v ...string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatSnapshots) WithHelp(v bool) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Help = &v
}
}
// WithIgnoreUnavailable - set to true to ignore unavailable snapshots.
//
func (f CatSnapshots) WithIgnoreUnavailable(v bool) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatSnapshots) WithMasterTimeout(v time.Duration) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatSnapshots) WithS(v ...string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatSnapshots) WithV(v bool) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatSnapshots) WithPretty() func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatSnapshots) WithHuman() func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatSnapshots) WithErrorTrace() func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatSnapshots) WithFilterPath(v ...string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatSnapshots) WithHeader(h map[string]string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,297 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newCatTasksFunc(t Transport) CatTasks {
return func(o ...func(*CatTasksRequest)) (*Response, error) {
var r = CatTasksRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatTasks returns information about the tasks currently executing on one or more nodes in the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html.
//
type CatTasks func(o ...func(*CatTasksRequest)) (*Response, error)
// CatTasksRequest configures the Cat Tasks API request.
//
type CatTasksRequest struct {
Actions []string
Detailed *bool
Format string
H []string
Help *bool
NodeID []string
ParentNode string
ParentTask *int
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cat/tasks"))
path.WriteString("/_cat/tasks")
params = make(map[string]string)
if len(r.Actions) > 0 {
params["actions"] = strings.Join(r.Actions, ",")
}
if r.Detailed != nil {
params["detailed"] = strconv.FormatBool(*r.Detailed)
}
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if len(r.NodeID) > 0 {
params["node_id"] = strings.Join(r.NodeID, ",")
}
if r.ParentNode != "" {
params["parent_node"] = r.ParentNode
}
if r.ParentTask != nil {
params["parent_task"] = strconv.FormatInt(int64(*r.ParentTask), 10)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatTasks) WithContext(v context.Context) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.ctx = v
}
}
// WithActions - a list of actions that should be returned. leave empty to return all..
//
func (f CatTasks) WithActions(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Actions = v
}
}
// WithDetailed - return detailed task information (default: false).
//
func (f CatTasks) WithDetailed(v bool) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Detailed = &v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatTasks) WithFormat(v string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatTasks) WithH(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatTasks) WithHelp(v bool) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Help = &v
}
}
// WithNodeID - 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 (f CatTasks) WithNodeID(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.NodeID = v
}
}
// WithParentNode - return tasks with specified parent node..
//
func (f CatTasks) WithParentNode(v string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.ParentNode = v
}
}
// WithParentTask - return tasks with specified parent task ID. set to -1 to return all..
//
func (f CatTasks) WithParentTask(v int) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.ParentTask = &v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatTasks) WithS(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatTasks) WithV(v bool) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatTasks) WithPretty() func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatTasks) WithHuman() func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatTasks) WithErrorTrace() func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatTasks) WithFilterPath(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatTasks) WithHeader(h map[string]string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,276 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatTemplatesFunc(t Transport) CatTemplates {
return func(o ...func(*CatTemplatesRequest)) (*Response, error) {
var r = CatTemplatesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatTemplates returns information about existing templates.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-templates.html.
//
type CatTemplates func(o ...func(*CatTemplatesRequest)) (*Response, error)
// CatTemplatesRequest configures the Cat Templates API request.
//
type CatTemplatesRequest struct {
Name string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatTemplatesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("templates") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("templates")
if r.Name != "" {
path.WriteString("/")
path.WriteString(r.Name)
}
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatTemplates) WithContext(v context.Context) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.ctx = v
}
}
// WithName - a pattern that returned template names must match.
//
func (f CatTemplates) WithName(v string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Name = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatTemplates) WithFormat(v string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatTemplates) WithH(v ...string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatTemplates) WithHelp(v bool) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatTemplates) WithLocal(v bool) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatTemplates) WithMasterTimeout(v time.Duration) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatTemplates) WithS(v ...string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.S = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatTemplates) WithV(v bool) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatTemplates) WithPretty() func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatTemplates) WithHuman() func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatTemplates) WithErrorTrace() func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatTemplates) WithFilterPath(v ...string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatTemplates) WithHeader(h map[string]string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,290 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatThreadPoolFunc(t Transport) CatThreadPool {
return func(o ...func(*CatThreadPoolRequest)) (*Response, error) {
var r = CatThreadPoolRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatThreadPool returns cluster-wide thread pool statistics per node.
// By default the active, queue and rejected statistics are returned for all thread pools.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-thread-pool.html.
//
type CatThreadPool func(o ...func(*CatThreadPoolRequest)) (*Response, error)
// CatThreadPoolRequest configures the Cat Thread Pool API request.
//
type CatThreadPoolRequest struct {
ThreadPoolPatterns []string
Format string
H []string
Help *bool
Local *bool
MasterTimeout time.Duration
S []string
Size string
V *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CatThreadPoolRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cat") + 1 + len("thread_pool") + 1 + len(strings.Join(r.ThreadPoolPatterns, ",")))
path.WriteString("/")
path.WriteString("_cat")
path.WriteString("/")
path.WriteString("thread_pool")
if len(r.ThreadPoolPatterns) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.ThreadPoolPatterns, ","))
}
params = make(map[string]string)
if r.Format != "" {
params["format"] = r.Format
}
if len(r.H) > 0 {
params["h"] = strings.Join(r.H, ",")
}
if r.Help != nil {
params["help"] = strconv.FormatBool(*r.Help)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Size != "" {
params["size"] = r.Size
}
if r.V != nil {
params["v"] = strconv.FormatBool(*r.V)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CatThreadPool) WithContext(v context.Context) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.ctx = v
}
}
// WithThreadPoolPatterns - a list of regular-expressions to filter the thread pools in the output.
//
func (f CatThreadPool) WithThreadPoolPatterns(v ...string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.ThreadPoolPatterns = v
}
}
// WithFormat - a short version of the accept header, e.g. json, yaml.
//
func (f CatThreadPool) WithFormat(v string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Format = v
}
}
// WithH - comma-separated list of column names to display.
//
func (f CatThreadPool) WithH(v ...string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.H = v
}
}
// WithHelp - return help information.
//
func (f CatThreadPool) WithHelp(v bool) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Help = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f CatThreadPool) WithLocal(v bool) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f CatThreadPool) WithMasterTimeout(v time.Duration) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.MasterTimeout = v
}
}
// WithS - comma-separated list of column names or column aliases to sort by.
//
func (f CatThreadPool) WithS(v ...string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.S = v
}
}
// WithSize - the multiplier in which to display values.
//
func (f CatThreadPool) WithSize(v string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Size = v
}
}
// WithV - verbose mode. display column headers.
//
func (f CatThreadPool) WithV(v bool) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.V = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CatThreadPool) WithPretty() func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CatThreadPool) WithHuman() func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CatThreadPool) WithErrorTrace() func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CatThreadPool) WithFilterPath(v ...string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CatThreadPool) WithHeader(h map[string]string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,197 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strings"
)
func newClearScrollFunc(t Transport) ClearScroll {
return func(o ...func(*ClearScrollRequest)) (*Response, error) {
var r = ClearScrollRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClearScroll explicitly clears the search context for a scroll.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-scroll.html.
//
type ClearScroll func(o ...func(*ClearScrollRequest)) (*Response, error)
// ClearScrollRequest configures the Clear Scroll API request.
//
type ClearScrollRequest struct {
Body io.Reader
ScrollID []string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClearScrollRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_search") + 1 + len("scroll") + 1 + len(strings.Join(r.ScrollID, ",")))
path.WriteString("/")
path.WriteString("_search")
path.WriteString("/")
path.WriteString("scroll")
if len(r.ScrollID) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.ScrollID, ","))
}
params = make(map[string]string)
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClearScroll) WithContext(v context.Context) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.ctx = v
}
}
// WithBody - A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter.
//
func (f ClearScroll) WithBody(v io.Reader) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.Body = v
}
}
// WithScrollID - a list of scroll ids to clear.
//
func (f ClearScroll) WithScrollID(v ...string) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.ScrollID = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClearScroll) WithPretty() func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClearScroll) WithHuman() func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClearScroll) WithErrorTrace() func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClearScroll) WithFilterPath(v ...string) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClearScroll) WithHeader(h map[string]string) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,208 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newClusterAllocationExplainFunc(t Transport) ClusterAllocationExplain {
return func(o ...func(*ClusterAllocationExplainRequest)) (*Response, error) {
var r = ClusterAllocationExplainRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterAllocationExplain provides explanations for shard allocations in the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-allocation-explain.html.
//
type ClusterAllocationExplain func(o ...func(*ClusterAllocationExplainRequest)) (*Response, error)
// ClusterAllocationExplainRequest configures the Cluster Allocation Explain API request.
//
type ClusterAllocationExplainRequest struct {
Body io.Reader
IncludeDiskInfo *bool
IncludeYesDecisions *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterAllocationExplainRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cluster/allocation/explain"))
path.WriteString("/_cluster/allocation/explain")
params = make(map[string]string)
if r.IncludeDiskInfo != nil {
params["include_disk_info"] = strconv.FormatBool(*r.IncludeDiskInfo)
}
if r.IncludeYesDecisions != nil {
params["include_yes_decisions"] = strconv.FormatBool(*r.IncludeYesDecisions)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterAllocationExplain) WithContext(v context.Context) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.ctx = v
}
}
// WithBody - The index, shard, and primary flag to explain. Empty means 'explain the first unassigned shard'.
//
func (f ClusterAllocationExplain) WithBody(v io.Reader) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.Body = v
}
}
// WithIncludeDiskInfo - return information about disk usage and shard sizes (default: false).
//
func (f ClusterAllocationExplain) WithIncludeDiskInfo(v bool) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.IncludeDiskInfo = &v
}
}
// WithIncludeYesDecisions - return 'yes' decisions in explanation (default: false).
//
func (f ClusterAllocationExplain) WithIncludeYesDecisions(v bool) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.IncludeYesDecisions = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterAllocationExplain) WithPretty() func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterAllocationExplain) WithHuman() func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterAllocationExplain) WithErrorTrace() func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterAllocationExplain) WithFilterPath(v ...string) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterAllocationExplain) WithHeader(h map[string]string) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,220 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterGetSettingsFunc(t Transport) ClusterGetSettings {
return func(o ...func(*ClusterGetSettingsRequest)) (*Response, error) {
var r = ClusterGetSettingsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterGetSettings returns cluster settings.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-update-settings.html.
//
type ClusterGetSettings func(o ...func(*ClusterGetSettingsRequest)) (*Response, error)
// ClusterGetSettingsRequest configures the Cluster Get Settings API request.
//
type ClusterGetSettingsRequest struct {
FlatSettings *bool
IncludeDefaults *bool
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterGetSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cluster/settings"))
path.WriteString("/_cluster/settings")
params = make(map[string]string)
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IncludeDefaults != nil {
params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterGetSettings) WithContext(v context.Context) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.ctx = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f ClusterGetSettings) WithFlatSettings(v bool) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.FlatSettings = &v
}
}
// WithIncludeDefaults - whether to return all default clusters setting..
//
func (f ClusterGetSettings) WithIncludeDefaults(v bool) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.IncludeDefaults = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterGetSettings) WithMasterTimeout(v time.Duration) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterGetSettings) WithTimeout(v time.Duration) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterGetSettings) WithPretty() func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterGetSettings) WithHuman() func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterGetSettings) WithErrorTrace() func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterGetSettings) WithFilterPath(v ...string) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterGetSettings) WithHeader(h map[string]string) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,302 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterHealthFunc(t Transport) ClusterHealth {
return func(o ...func(*ClusterHealthRequest)) (*Response, error) {
var r = ClusterHealthRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterHealth returns basic information about the health of the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-health.html.
//
type ClusterHealth func(o ...func(*ClusterHealthRequest)) (*Response, error)
// ClusterHealthRequest configures the Cluster Health API request.
//
type ClusterHealthRequest struct {
Index []string
Level string
Local *bool
MasterTimeout time.Duration
Timeout time.Duration
WaitForActiveShards string
WaitForEvents string
WaitForNoRelocatingShards *bool
WaitForNodes string
WaitForStatus string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterHealthRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cluster") + 1 + len("health") + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cluster")
path.WriteString("/")
path.WriteString("health")
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.Level != "" {
params["level"] = r.Level
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.WaitForEvents != "" {
params["wait_for_events"] = r.WaitForEvents
}
if r.WaitForNoRelocatingShards != nil {
params["wait_for_no_relocating_shards"] = strconv.FormatBool(*r.WaitForNoRelocatingShards)
}
if r.WaitForNodes != "" {
params["wait_for_nodes"] = r.WaitForNodes
}
if r.WaitForStatus != "" {
params["wait_for_status"] = r.WaitForStatus
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterHealth) WithContext(v context.Context) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.ctx = v
}
}
// WithIndex - limit the information returned to a specific index.
//
func (f ClusterHealth) WithIndex(v ...string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Index = v
}
}
// WithLevel - specify the level of detail for returned information.
//
func (f ClusterHealth) WithLevel(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Level = v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f ClusterHealth) WithLocal(v bool) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterHealth) WithMasterTimeout(v time.Duration) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterHealth) WithTimeout(v time.Duration) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Timeout = v
}
}
// WithWaitForActiveShards - wait until the specified number of shards is active.
//
func (f ClusterHealth) WithWaitForActiveShards(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForActiveShards = v
}
}
// WithWaitForEvents - wait until all currently queued events with the given priority are processed.
//
func (f ClusterHealth) WithWaitForEvents(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForEvents = v
}
}
// WithWaitForNoRelocatingShards - whether to wait until there are no relocating shards in the cluster.
//
func (f ClusterHealth) WithWaitForNoRelocatingShards(v bool) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForNoRelocatingShards = &v
}
}
// WithWaitForNodes - wait until the specified number of nodes is available.
//
func (f ClusterHealth) WithWaitForNodes(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForNodes = v
}
}
// WithWaitForStatus - wait until cluster is in a specific state.
//
func (f ClusterHealth) WithWaitForStatus(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForStatus = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterHealth) WithPretty() func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterHealth) WithHuman() func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterHealth) WithErrorTrace() func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterHealth) WithFilterPath(v ...string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterHealth) WithHeader(h map[string]string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,195 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterPendingTasksFunc(t Transport) ClusterPendingTasks {
return func(o ...func(*ClusterPendingTasksRequest)) (*Response, error) {
var r = ClusterPendingTasksRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterPendingTasks returns a list of any cluster-level changes (e.g. create index, update mapping,
// allocate or fail shard) which have not yet been executed.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-pending.html.
//
type ClusterPendingTasks func(o ...func(*ClusterPendingTasksRequest)) (*Response, error)
// ClusterPendingTasksRequest configures the Cluster Pending Tasks API request.
//
type ClusterPendingTasksRequest struct {
Local *bool
MasterTimeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterPendingTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_cluster/pending_tasks"))
path.WriteString("/_cluster/pending_tasks")
params = make(map[string]string)
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterPendingTasks) WithContext(v context.Context) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.ctx = v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f ClusterPendingTasks) WithLocal(v bool) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.Local = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f ClusterPendingTasks) WithMasterTimeout(v time.Duration) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterPendingTasks) WithPretty() func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterPendingTasks) WithHuman() func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterPendingTasks) WithErrorTrace() func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterPendingTasks) WithFilterPath(v ...string) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterPendingTasks) WithHeader(h map[string]string) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,222 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterPutSettingsFunc(t Transport) ClusterPutSettings {
return func(o ...func(*ClusterPutSettingsRequest)) (*Response, error) {
var r = ClusterPutSettingsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterPutSettings updates the cluster settings.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-update-settings.html.
//
type ClusterPutSettings func(o ...func(*ClusterPutSettingsRequest)) (*Response, error)
// ClusterPutSettingsRequest configures the Cluster Put Settings API request.
//
type ClusterPutSettingsRequest struct {
Body io.Reader
FlatSettings *bool
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterPutSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(len("/_cluster/settings"))
path.WriteString("/_cluster/settings")
params = make(map[string]string)
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterPutSettings) WithContext(v context.Context) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.ctx = v
}
}
// WithBody - The settings to be updated. Can be either `transient` or `persistent` (survives cluster restart)..
//
func (f ClusterPutSettings) WithBody(v io.Reader) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.Body = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f ClusterPutSettings) WithFlatSettings(v bool) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.FlatSettings = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterPutSettings) WithMasterTimeout(v time.Duration) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterPutSettings) WithTimeout(v time.Duration) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterPutSettings) WithPretty() func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterPutSettings) WithHuman() func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterPutSettings) WithErrorTrace() func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterPutSettings) WithFilterPath(v ...string) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterPutSettings) WithHeader(h map[string]string) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,165 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
)
func newClusterRemoteInfoFunc(t Transport) ClusterRemoteInfo {
return func(o ...func(*ClusterRemoteInfoRequest)) (*Response, error) {
var r = ClusterRemoteInfoRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterRemoteInfo returns the information about configured remote clusters.
//
// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-remote-info.html.
//
type ClusterRemoteInfo func(o ...func(*ClusterRemoteInfoRequest)) (*Response, error)
// ClusterRemoteInfoRequest configures the Cluster Remote Info API request.
//
type ClusterRemoteInfoRequest struct {
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterRemoteInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_remote/info"))
path.WriteString("/_remote/info")
params = make(map[string]string)
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterRemoteInfo) WithContext(v context.Context) func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterRemoteInfo) WithPretty() func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterRemoteInfo) WithHuman() func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterRemoteInfo) WithErrorTrace() func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterRemoteInfo) WithFilterPath(v ...string) func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterRemoteInfo) WithHeader(h map[string]string) func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,261 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterRerouteFunc(t Transport) ClusterReroute {
return func(o ...func(*ClusterRerouteRequest)) (*Response, error) {
var r = ClusterRerouteRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterReroute allows to manually change the allocation of individual shards in the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-reroute.html.
//
type ClusterReroute func(o ...func(*ClusterRerouteRequest)) (*Response, error)
// ClusterRerouteRequest configures the Cluster Reroute API request.
//
type ClusterRerouteRequest struct {
Body io.Reader
DryRun *bool
Explain *bool
MasterTimeout time.Duration
Metric []string
RetryFailed *bool
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterRerouteRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(len("/_cluster/reroute"))
path.WriteString("/_cluster/reroute")
params = make(map[string]string)
if r.DryRun != nil {
params["dry_run"] = strconv.FormatBool(*r.DryRun)
}
if r.Explain != nil {
params["explain"] = strconv.FormatBool(*r.Explain)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if len(r.Metric) > 0 {
params["metric"] = strings.Join(r.Metric, ",")
}
if r.RetryFailed != nil {
params["retry_failed"] = strconv.FormatBool(*r.RetryFailed)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterReroute) WithContext(v context.Context) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.ctx = v
}
}
// WithBody - The definition of `commands` to perform (`move`, `cancel`, `allocate`).
//
func (f ClusterReroute) WithBody(v io.Reader) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Body = v
}
}
// WithDryRun - simulate the operation only and return the resulting state.
//
func (f ClusterReroute) WithDryRun(v bool) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.DryRun = &v
}
}
// WithExplain - return an explanation of why the commands can or cannot be executed.
//
func (f ClusterReroute) WithExplain(v bool) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Explain = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterReroute) WithMasterTimeout(v time.Duration) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.MasterTimeout = v
}
}
// WithMetric - limit the information returned to the specified metrics. defaults to all but metadata.
//
func (f ClusterReroute) WithMetric(v ...string) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Metric = v
}
}
// WithRetryFailed - retries allocation of shards that are blocked due to too many subsequent allocation failures.
//
func (f ClusterReroute) WithRetryFailed(v bool) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.RetryFailed = &v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterReroute) WithTimeout(v time.Duration) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterReroute) WithPretty() func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterReroute) WithHuman() func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterReroute) WithErrorTrace() func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterReroute) WithFilterPath(v ...string) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterReroute) WithHeader(h map[string]string) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,277 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterStateFunc(t Transport) ClusterState {
return func(o ...func(*ClusterStateRequest)) (*Response, error) {
var r = ClusterStateRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterState returns a comprehensive information about the state of the cluster.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-state.html.
//
type ClusterState func(o ...func(*ClusterStateRequest)) (*Response, error)
// ClusterStateRequest configures the Cluster State API request.
//
type ClusterStateRequest struct {
Index []string
Metric []string
AllowNoIndices *bool
ExpandWildcards string
FlatSettings *bool
IgnoreUnavailable *bool
Local *bool
MasterTimeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterStateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_cluster") + 1 + len("state") + 1 + len(strings.Join(r.Metric, ",")) + 1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString("_cluster")
path.WriteString("/")
path.WriteString("state")
if len(r.Metric) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Metric, ","))
}
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterState) WithContext(v context.Context) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f ClusterState) WithIndex(v ...string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.Index = v
}
}
// WithMetric - limit the information returned to the specified metrics.
//
func (f ClusterState) WithMetric(v ...string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.Metric = v
}
}
// WithAllowNoIndices - 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 (f ClusterState) WithAllowNoIndices(v bool) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f ClusterState) WithExpandWildcards(v string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.ExpandWildcards = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f ClusterState) WithFlatSettings(v bool) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.FlatSettings = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f ClusterState) WithIgnoreUnavailable(v bool) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f ClusterState) WithLocal(v bool) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f ClusterState) WithMasterTimeout(v time.Duration) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterState) WithPretty() func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterState) WithHuman() func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterState) WithErrorTrace() func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterState) WithFilterPath(v ...string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterState) WithHeader(h map[string]string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,213 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterStatsFunc(t Transport) ClusterStats {
return func(o ...func(*ClusterStatsRequest)) (*Response, error) {
var r = ClusterStatsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterStats returns high-level overview of cluster statistics.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-stats.html.
//
type ClusterStats func(o ...func(*ClusterStatsRequest)) (*Response, error)
// ClusterStatsRequest configures the Cluster Stats API request.
//
type ClusterStatsRequest struct {
NodeID []string
FlatSettings *bool
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ClusterStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/nodes/_cluster/stats/nodes/") + len(strings.Join(r.NodeID, ",")))
path.WriteString("/")
path.WriteString("_cluster")
path.WriteString("/")
path.WriteString("stats")
if len(r.NodeID) > 0 {
path.WriteString("/")
path.WriteString("nodes")
path.WriteString("/")
path.WriteString(strings.Join(r.NodeID, ","))
}
params = make(map[string]string)
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ClusterStats) WithContext(v context.Context) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.ctx = v
}
}
// WithNodeID - 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 (f ClusterStats) WithNodeID(v ...string) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.NodeID = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f ClusterStats) WithFlatSettings(v bool) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.FlatSettings = &v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterStats) WithTimeout(v time.Duration) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterStats) WithPretty() func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterStats) WithHuman() func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterStats) WithErrorTrace() func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterStats) WithFilterPath(v ...string) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterStats) WithHeader(h map[string]string) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,379 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newCountFunc(t Transport) Count {
return func(o ...func(*CountRequest)) (*Response, error) {
var r = CountRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Count returns number of documents matching a query.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-count.html.
//
type Count func(o ...func(*CountRequest)) (*Response, error)
// CountRequest configures the Count API request.
//
type CountRequest struct {
Index []string
DocumentType []string
Body io.Reader
AllowNoIndices *bool
Analyzer string
AnalyzeWildcard *bool
DefaultOperator string
Df string
ExpandWildcards string
IgnoreUnavailable *bool
Lenient *bool
MinScore *int
Preference string
Query string
Routing []string
TerminateAfter *int
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CountRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len(strings.Join(r.DocumentType, ",")) + 1 + len("_count"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
if len(r.DocumentType) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.DocumentType, ","))
}
path.WriteString("/")
path.WriteString("_count")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.Analyzer != "" {
params["analyzer"] = r.Analyzer
}
if r.AnalyzeWildcard != nil {
params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard)
}
if r.DefaultOperator != "" {
params["default_operator"] = r.DefaultOperator
}
if r.Df != "" {
params["df"] = r.Df
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Lenient != nil {
params["lenient"] = strconv.FormatBool(*r.Lenient)
}
if r.MinScore != nil {
params["min_score"] = strconv.FormatInt(int64(*r.MinScore), 10)
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Query != "" {
params["q"] = r.Query
}
if len(r.Routing) > 0 {
params["routing"] = strings.Join(r.Routing, ",")
}
if r.TerminateAfter != nil {
params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Count) WithContext(v context.Context) func(*CountRequest) {
return func(r *CountRequest) {
r.ctx = v
}
}
// WithBody - A query to restrict the results specified with the Query DSL (optional).
//
func (f Count) WithBody(v io.Reader) func(*CountRequest) {
return func(r *CountRequest) {
r.Body = v
}
}
// WithIndex - a list of indices to restrict the results.
//
func (f Count) WithIndex(v ...string) func(*CountRequest) {
return func(r *CountRequest) {
r.Index = v
}
}
// WithDocumentType - a list of types to restrict the results.
//
func (f Count) WithDocumentType(v ...string) func(*CountRequest) {
return func(r *CountRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f Count) WithAllowNoIndices(v bool) func(*CountRequest) {
return func(r *CountRequest) {
r.AllowNoIndices = &v
}
}
// WithAnalyzer - the analyzer to use for the query string.
//
func (f Count) WithAnalyzer(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.Analyzer = v
}
}
// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false).
//
func (f Count) WithAnalyzeWildcard(v bool) func(*CountRequest) {
return func(r *CountRequest) {
r.AnalyzeWildcard = &v
}
}
// WithDefaultOperator - the default operator for query string query (and or or).
//
func (f Count) WithDefaultOperator(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.DefaultOperator = v
}
}
// WithDf - the field to use as default where no field prefix is given in the query string.
//
func (f Count) WithDf(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.Df = v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f Count) WithExpandWildcards(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f Count) WithIgnoreUnavailable(v bool) func(*CountRequest) {
return func(r *CountRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored.
//
func (f Count) WithLenient(v bool) func(*CountRequest) {
return func(r *CountRequest) {
r.Lenient = &v
}
}
// WithMinScore - include only documents with a specific `_score` value in the result.
//
func (f Count) WithMinScore(v int) func(*CountRequest) {
return func(r *CountRequest) {
r.MinScore = &v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f Count) WithPreference(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.Preference = v
}
}
// WithQuery - query in the lucene query string syntax.
//
func (f Count) WithQuery(v string) func(*CountRequest) {
return func(r *CountRequest) {
r.Query = v
}
}
// WithRouting - a list of specific routing values.
//
func (f Count) WithRouting(v ...string) func(*CountRequest) {
return func(r *CountRequest) {
r.Routing = v
}
}
// WithTerminateAfter - the maximum count for each shard, upon reaching which the query execution will terminate early.
//
func (f Count) WithTerminateAfter(v int) func(*CountRequest) {
return func(r *CountRequest) {
r.TerminateAfter = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Count) WithPretty() func(*CountRequest) {
return func(r *CountRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Count) WithHuman() func(*CountRequest) {
return func(r *CountRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Count) WithErrorTrace() func(*CountRequest) {
return func(r *CountRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Count) WithFilterPath(v ...string) func(*CountRequest) {
return func(r *CountRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Count) WithHeader(h map[string]string) func(*CountRequest) {
return func(r *CountRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,329 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newCountPercolateFunc(t Transport) CountPercolate {
return func(index string, o ...func(*CountPercolateRequest)) (*Response, error) {
var r = CountPercolateRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-percolate.html.
//
type CountPercolate func(index string, o ...func(*CountPercolateRequest)) (*Response, error)
// CountPercolateRequest configures the Count Percolate API request.
//
type CountPercolateRequest struct {
Index string
DocumentType string
DocumentID string
Body io.Reader
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
PercolateIndex string
PercolateType string
Preference string
Routing []string
Version *int
VersionType string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CountPercolateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_percolate") + 1 + len("count"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
if r.DocumentID != "" {
path.WriteString("/")
path.WriteString(r.DocumentID)
}
path.WriteString("/")
path.WriteString("_percolate")
path.WriteString("/")
path.WriteString("count")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.PercolateIndex != "" {
params["percolate_index"] = r.PercolateIndex
}
if r.PercolateType != "" {
params["percolate_type"] = r.PercolateType
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if len(r.Routing) > 0 {
params["routing"] = strings.Join(r.Routing, ",")
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f CountPercolate) WithContext(v context.Context) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.ctx = v
}
}
// WithBody - The count percolator request definition using the percolate DSL.
//
func (f CountPercolate) WithBody(v io.Reader) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Body = v
}
}
// WithDocumentID - substitute the document in the request body with a document that is known by the specified ID. on top of the ID, the index and type parameter will be used to retrieve the document from within the cluster..
//
func (f CountPercolate) WithDocumentID(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.DocumentID = v
}
}
// WithDocumentType - the type of the document being count percolated..
//
func (f CountPercolate) WithDocumentType(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f CountPercolate) WithAllowNoIndices(v bool) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f CountPercolate) WithExpandWildcards(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f CountPercolate) WithIgnoreUnavailable(v bool) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPercolateIndex - the index to count percolate the document into. defaults to index..
//
func (f CountPercolate) WithPercolateIndex(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.PercolateIndex = v
}
}
// WithPercolateType - the type to count percolate document into. defaults to type..
//
func (f CountPercolate) WithPercolateType(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.PercolateType = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f CountPercolate) WithPreference(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Preference = v
}
}
// WithRouting - a list of specific routing values.
//
func (f CountPercolate) WithRouting(v ...string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Routing = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f CountPercolate) WithVersion(v int) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f CountPercolate) WithVersionType(v string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.VersionType = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f CountPercolate) WithPretty() func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f CountPercolate) WithHuman() func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f CountPercolate) WithErrorTrace() func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f CountPercolate) WithFilterPath(v ...string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f CountPercolate) WithHeader(h map[string]string) func(*CountPercolateRequest) {
return func(r *CountPercolateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,330 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newCreateFunc(t Transport) Create {
return func(index string, id string, body io.Reader, o ...func(*CreateRequest)) (*Response, error) {
var r = CreateRequest{Index: index, DocumentID: id, Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Create creates a new document in the index.
//
// Returns a 409 response when a document with a same ID already exists in the index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-index_.html.
//
type Create func(index string, id string, body io.Reader, o ...func(*CreateRequest)) (*Response, error)
// CreateRequest configures the Create API request.
//
type CreateRequest struct {
Index string
DocumentType string
DocumentID string
Body io.Reader
Parent string
Pipeline string
Refresh string
Routing string
Timeout time.Duration
Timestamp time.Duration
TTL time.Duration
Version *int
VersionType string
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r CreateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_create"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_create")
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Pipeline != "" {
params["pipeline"] = r.Pipeline
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Timestamp != 0 {
params["timestamp"] = formatDuration(r.Timestamp)
}
if r.TTL != 0 {
params["ttl"] = formatDuration(r.TTL)
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Create) WithContext(v context.Context) func(*CreateRequest) {
return func(r *CreateRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document.
//
func (f Create) WithDocumentType(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.DocumentType = v
}
}
// WithParent - ID of the parent document.
//
func (f Create) WithParent(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Parent = v
}
}
// WithPipeline - the pipeline ID to preprocess incoming documents with.
//
func (f Create) WithPipeline(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Pipeline = v
}
}
// WithRefresh - if `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes..
//
func (f Create) WithRefresh(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Refresh = v
}
}
// WithRouting - specific routing value.
//
func (f Create) WithRouting(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Routing = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f Create) WithTimeout(v time.Duration) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Timeout = v
}
}
// WithTimestamp - explicit timestamp for the document.
//
func (f Create) WithTimestamp(v time.Duration) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Timestamp = v
}
}
// WithTTL - expiration time for the document.
//
func (f Create) WithTTL(v time.Duration) func(*CreateRequest) {
return func(r *CreateRequest) {
r.TTL = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f Create) WithVersion(v int) func(*CreateRequest) {
return func(r *CreateRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f Create) WithVersionType(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.VersionType = v
}
}
// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the index operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1).
//
func (f Create) WithWaitForActiveShards(v string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Create) WithPretty() func(*CreateRequest) {
return func(r *CreateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Create) WithHuman() func(*CreateRequest) {
return func(r *CreateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Create) WithErrorTrace() func(*CreateRequest) {
return func(r *CreateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Create) WithFilterPath(v ...string) func(*CreateRequest) {
return func(r *CreateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Create) WithHeader(h map[string]string) func(*CreateRequest) {
return func(r *CreateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,280 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newDeleteFunc(t Transport) Delete {
return func(index string, id string, o ...func(*DeleteRequest)) (*Response, error) {
var r = DeleteRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Delete removes a document from the index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-delete.html.
//
type Delete func(index string, id string, o ...func(*DeleteRequest)) (*Response, error)
// DeleteRequest configures the Delete API request.
//
type DeleteRequest struct {
Index string
DocumentType string
DocumentID string
Parent string
Refresh string
Routing string
Timeout time.Duration
Version *int
VersionType string
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r DeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Delete) WithContext(v context.Context) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document.
//
func (f Delete) WithDocumentType(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.DocumentType = v
}
}
// WithParent - ID of parent document.
//
func (f Delete) WithParent(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Parent = v
}
}
// WithRefresh - if `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes..
//
func (f Delete) WithRefresh(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Refresh = v
}
}
// WithRouting - specific routing value.
//
func (f Delete) WithRouting(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Routing = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f Delete) WithTimeout(v time.Duration) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Timeout = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f Delete) WithVersion(v int) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f Delete) WithVersionType(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.VersionType = v
}
}
// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the delete operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1).
//
func (f Delete) WithWaitForActiveShards(v string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Delete) WithPretty() func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Delete) WithHuman() func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Delete) WithErrorTrace() func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Delete) WithFilterPath(v ...string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Delete) WithHeader(h map[string]string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,609 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newDeleteByQueryFunc(t Transport) DeleteByQuery {
return func(index []string, body io.Reader, o ...func(*DeleteByQueryRequest)) (*Response, error) {
var r = DeleteByQueryRequest{Index: index, Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DeleteByQuery deletes documents matching the provided query.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-delete-by-query.html.
//
type DeleteByQuery func(index []string, body io.Reader, o ...func(*DeleteByQueryRequest)) (*Response, error)
// DeleteByQueryRequest configures the Delete By Query API request.
//
type DeleteByQueryRequest struct {
Index []string
DocumentType []string
Body io.Reader
AllowNoIndices *bool
Analyzer string
AnalyzeWildcard *bool
Conflicts string
DefaultOperator string
Df string
ExpandWildcards string
From *int
IgnoreUnavailable *bool
Lenient *bool
Preference string
Query string
Refresh *bool
RequestCache *bool
RequestsPerSecond *int
Routing []string
Scroll time.Duration
ScrollSize *int
SearchTimeout time.Duration
SearchType string
Size *int
Slices *int
Sort []string
Source []string
SourceExclude []string
SourceInclude []string
Stats []string
TerminateAfter *int
Timeout time.Duration
Version *bool
WaitForActiveShards string
WaitForCompletion *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r DeleteByQueryRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len(strings.Join(r.DocumentType, ",")) + 1 + len("_delete_by_query"))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
if len(r.DocumentType) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.DocumentType, ","))
}
path.WriteString("/")
path.WriteString("_delete_by_query")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.Analyzer != "" {
params["analyzer"] = r.Analyzer
}
if r.AnalyzeWildcard != nil {
params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard)
}
if r.Conflicts != "" {
params["conflicts"] = r.Conflicts
}
if r.DefaultOperator != "" {
params["default_operator"] = r.DefaultOperator
}
if r.Df != "" {
params["df"] = r.Df
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.From != nil {
params["from"] = strconv.FormatInt(int64(*r.From), 10)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Lenient != nil {
params["lenient"] = strconv.FormatBool(*r.Lenient)
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Query != "" {
params["q"] = r.Query
}
if r.Refresh != nil {
params["refresh"] = strconv.FormatBool(*r.Refresh)
}
if r.RequestCache != nil {
params["request_cache"] = strconv.FormatBool(*r.RequestCache)
}
if r.RequestsPerSecond != nil {
params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10)
}
if len(r.Routing) > 0 {
params["routing"] = strings.Join(r.Routing, ",")
}
if r.Scroll != 0 {
params["scroll"] = formatDuration(r.Scroll)
}
if r.ScrollSize != nil {
params["scroll_size"] = strconv.FormatInt(int64(*r.ScrollSize), 10)
}
if r.SearchTimeout != 0 {
params["search_timeout"] = formatDuration(r.SearchTimeout)
}
if r.SearchType != "" {
params["search_type"] = r.SearchType
}
if r.Size != nil {
params["size"] = strconv.FormatInt(int64(*r.Size), 10)
}
if r.Slices != nil {
params["slices"] = strconv.FormatInt(int64(*r.Slices), 10)
}
if len(r.Sort) > 0 {
params["sort"] = strings.Join(r.Sort, ",")
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if len(r.Stats) > 0 {
params["stats"] = strings.Join(r.Stats, ",")
}
if r.TerminateAfter != nil {
params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Version != nil {
params["version"] = strconv.FormatBool(*r.Version)
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.WaitForCompletion != nil {
params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f DeleteByQuery) WithContext(v context.Context) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.ctx = v
}
}
// WithDocumentType - a list of document types to search; leave empty to perform the operation on all types.
//
func (f DeleteByQuery) WithDocumentType(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f DeleteByQuery) WithAllowNoIndices(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.AllowNoIndices = &v
}
}
// WithAnalyzer - the analyzer to use for the query string.
//
func (f DeleteByQuery) WithAnalyzer(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Analyzer = v
}
}
// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false).
//
func (f DeleteByQuery) WithAnalyzeWildcard(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.AnalyzeWildcard = &v
}
}
// WithConflicts - what to do when the delete-by-query hits version conflicts?.
//
func (f DeleteByQuery) WithConflicts(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Conflicts = v
}
}
// WithDefaultOperator - the default operator for query string query (and or or).
//
func (f DeleteByQuery) WithDefaultOperator(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.DefaultOperator = v
}
}
// WithDf - the field to use as default where no field prefix is given in the query string.
//
func (f DeleteByQuery) WithDf(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Df = v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f DeleteByQuery) WithExpandWildcards(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.ExpandWildcards = v
}
}
// WithFrom - starting offset (default: 0).
//
func (f DeleteByQuery) WithFrom(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.From = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f DeleteByQuery) WithIgnoreUnavailable(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored.
//
func (f DeleteByQuery) WithLenient(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Lenient = &v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f DeleteByQuery) WithPreference(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Preference = v
}
}
// WithQuery - query in the lucene query string syntax.
//
func (f DeleteByQuery) WithQuery(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Query = v
}
}
// WithRefresh - should the effected indexes be refreshed?.
//
func (f DeleteByQuery) WithRefresh(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Refresh = &v
}
}
// WithRequestCache - specify if request cache should be used for this request or not, defaults to index level setting.
//
func (f DeleteByQuery) WithRequestCache(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.RequestCache = &v
}
}
// WithRequestsPerSecond - the throttle for this request in sub-requests per second. -1 means no throttle..
//
func (f DeleteByQuery) WithRequestsPerSecond(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.RequestsPerSecond = &v
}
}
// WithRouting - a list of specific routing values.
//
func (f DeleteByQuery) WithRouting(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Routing = v
}
}
// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search.
//
func (f DeleteByQuery) WithScroll(v time.Duration) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Scroll = v
}
}
// WithScrollSize - size on the scroll request powering the update_by_query.
//
func (f DeleteByQuery) WithScrollSize(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.ScrollSize = &v
}
}
// WithSearchTimeout - explicit timeout for each search request. defaults to no timeout..
//
func (f DeleteByQuery) WithSearchTimeout(v time.Duration) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SearchTimeout = v
}
}
// WithSearchType - search operation type.
//
func (f DeleteByQuery) WithSearchType(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SearchType = v
}
}
// WithSize - number of hits to return (default: 10).
//
func (f DeleteByQuery) WithSize(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Size = &v
}
}
// WithSlices - the number of slices this task should be divided into. defaults to 1 meaning the task isn't sliced into subtasks..
//
func (f DeleteByQuery) WithSlices(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Slices = &v
}
}
// WithSort - a list of <field>:<direction> pairs.
//
func (f DeleteByQuery) WithSort(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Sort = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f DeleteByQuery) WithSource(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f DeleteByQuery) WithSourceExclude(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f DeleteByQuery) WithSourceInclude(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SourceInclude = v
}
}
// WithStats - specific 'tag' of the request for logging and statistical purposes.
//
func (f DeleteByQuery) WithStats(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Stats = v
}
}
// WithTerminateAfter - the maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early..
//
func (f DeleteByQuery) WithTerminateAfter(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.TerminateAfter = &v
}
}
// WithTimeout - time each individual bulk request should wait for shards that are unavailable..
//
func (f DeleteByQuery) WithTimeout(v time.Duration) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Timeout = v
}
}
// WithVersion - specify whether to return document version as part of a hit.
//
func (f DeleteByQuery) WithVersion(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Version = &v
}
}
// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the delete by query operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1).
//
func (f DeleteByQuery) WithWaitForActiveShards(v string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.WaitForActiveShards = v
}
}
// WithWaitForCompletion - should the request should block until the delete-by-query is complete..
//
func (f DeleteByQuery) WithWaitForCompletion(v bool) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.WaitForCompletion = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DeleteByQuery) WithPretty() func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DeleteByQuery) WithHuman() func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DeleteByQuery) WithErrorTrace() func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DeleteByQuery) WithFilterPath(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DeleteByQuery) WithHeader(h map[string]string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,158 @@
// Code generated from specification version 7.0.0 (5e798c1): DO NOT EDIT
package esapi
import (
"context"
"strconv"
"strings"
)
func newDeleteByQueryRethrottleFunc(t Transport) DeleteByQueryRethrottle {
return func(task_id string, requests_per_second *int, o ...func(*DeleteByQueryRethrottleRequest)) (*Response, error) {
var r = DeleteByQueryRethrottleRequest{TaskID: task_id, RequestsPerSecond: requests_per_second}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DeleteByQueryRethrottle changes the number of requests per second for a particular Delete By Query operation.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html.
//
type DeleteByQueryRethrottle func(task_id string, requests_per_second *int, o ...func(*DeleteByQueryRethrottleRequest)) (*Response, error)
// DeleteByQueryRethrottleRequest configures the Delete By Query Rethrottle API request.
//
type DeleteByQueryRethrottleRequest struct {
TaskID string
RequestsPerSecond *int
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r DeleteByQueryRethrottleRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len("_delete_by_query") + 1 + len(r.TaskID) + 1 + len("_rethrottle"))
path.WriteString("/")
path.WriteString("_delete_by_query")
path.WriteString("/")
path.WriteString(r.TaskID)
path.WriteString("/")
path.WriteString("_rethrottle")
params = make(map[string]string)
if r.RequestsPerSecond != nil {
params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f DeleteByQueryRethrottle) WithContext(v context.Context) func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.ctx = v
}
}
// WithRequestsPerSecond - the throttle to set on this request in floating sub-requests per second. -1 means set no throttle..
//
func (f DeleteByQueryRethrottle) WithRequestsPerSecond(v int) func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.RequestsPerSecond = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DeleteByQueryRethrottle) WithPretty() func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DeleteByQueryRethrottle) WithHuman() func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DeleteByQueryRethrottle) WithErrorTrace() func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DeleteByQueryRethrottle) WithFilterPath(v ...string) func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
r.FilterPath = v
}
}

View File

@@ -0,0 +1,202 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
"time"
)
func newDeleteScriptFunc(t Transport) DeleteScript {
return func(id string, lang string, o ...func(*DeleteScriptRequest)) (*Response, error) {
var r = DeleteScriptRequest{ScriptID: id, Lang: lang}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DeleteScript deletes a script.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting.html.
//
type DeleteScript func(id string, lang string, o ...func(*DeleteScriptRequest)) (*Response, error)
// DeleteScriptRequest configures the Delete Script API request.
//
type DeleteScriptRequest struct {
ScriptID string
Lang string
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r DeleteScriptRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_scripts") + 1 + len(r.Lang) + 1 + len(r.ScriptID))
path.WriteString("/")
path.WriteString("_scripts")
path.WriteString("/")
path.WriteString(r.Lang)
path.WriteString("/")
path.WriteString(r.ScriptID)
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f DeleteScript) WithContext(v context.Context) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f DeleteScript) WithMasterTimeout(v time.Duration) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f DeleteScript) WithTimeout(v time.Duration) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DeleteScript) WithPretty() func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DeleteScript) WithHuman() func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DeleteScript) WithErrorTrace() func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DeleteScript) WithFilterPath(v ...string) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DeleteScript) WithHeader(h map[string]string) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,171 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
)
func newDeleteTemplateFunc(t Transport) DeleteTemplate {
return func(id string, o ...func(*DeleteTemplateRequest)) (*Response, error) {
var r = DeleteTemplateRequest{DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-template.html.
//
type DeleteTemplate func(id string, o ...func(*DeleteTemplateRequest)) (*Response, error)
// DeleteTemplateRequest configures the Delete Template API request.
//
type DeleteTemplateRequest struct {
DocumentID string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r DeleteTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_search") + 1 + len("template") + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString("_search")
path.WriteString("/")
path.WriteString("template")
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f DeleteTemplate) WithContext(v context.Context) func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DeleteTemplate) WithPretty() func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DeleteTemplate) WithHuman() func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DeleteTemplate) WithErrorTrace() func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DeleteTemplate) WithFilterPath(v ...string) func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DeleteTemplate) WithHeader(h map[string]string) func(*DeleteTemplateRequest) {
return func(r *DeleteTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,331 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newExistsFunc(t Transport) Exists {
return func(index string, id string, o ...func(*ExistsRequest)) (*Response, error) {
var r = ExistsRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Exists returns information about whether a document exists in an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html.
//
type Exists func(index string, id string, o ...func(*ExistsRequest)) (*Response, error)
// ExistsRequest configures the Exists API request.
//
type ExistsRequest struct {
Index string
DocumentType string
DocumentID string
Parent string
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExclude []string
SourceInclude []string
StoredFields []string
Version *int
VersionType string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ExistsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Realtime != nil {
params["realtime"] = strconv.FormatBool(*r.Realtime)
}
if r.Refresh != nil {
params["refresh"] = strconv.FormatBool(*r.Refresh)
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if len(r.StoredFields) > 0 {
params["stored_fields"] = strings.Join(r.StoredFields, ",")
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Exists) WithContext(v context.Context) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document (use `_all` to fetch the first document matching the ID across all types).
//
func (f Exists) WithDocumentType(v string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.DocumentType = v
}
}
// WithParent - the ID of the parent document.
//
func (f Exists) WithParent(v string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Parent = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f Exists) WithPreference(v string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Preference = v
}
}
// WithRealtime - specify whether to perform the operation in realtime or search mode.
//
func (f Exists) WithRealtime(v bool) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Realtime = &v
}
}
// WithRefresh - refresh the shard containing the document before performing the operation.
//
func (f Exists) WithRefresh(v bool) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Refresh = &v
}
}
// WithRouting - specific routing value.
//
func (f Exists) WithRouting(v string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f Exists) WithSource(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f Exists) WithSourceExclude(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f Exists) WithSourceInclude(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.SourceInclude = v
}
}
// WithStoredFields - a list of stored fields to return in the response.
//
func (f Exists) WithStoredFields(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.StoredFields = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f Exists) WithVersion(v int) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f Exists) WithVersionType(v string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.VersionType = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Exists) WithPretty() func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Exists) WithHuman() func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Exists) WithErrorTrace() func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Exists) WithFilterPath(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Exists) WithHeader(h map[string]string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,316 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newExistsSourceFunc(t Transport) ExistsSource {
return func(index string, id string, o ...func(*ExistsSourceRequest)) (*Response, error) {
var r = ExistsSourceRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ExistsSource returns information about whether a document source exists in an index.
//
// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html.
//
type ExistsSource func(index string, id string, o ...func(*ExistsSourceRequest)) (*Response, error)
// ExistsSourceRequest configures the Exists Source API request.
//
type ExistsSourceRequest struct {
Index string
DocumentType string
DocumentID string
Parent string
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExclude []string
SourceInclude []string
Version *int
VersionType string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ExistsSourceRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_source"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_source")
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Realtime != nil {
params["realtime"] = strconv.FormatBool(*r.Realtime)
}
if r.Refresh != nil {
params["refresh"] = strconv.FormatBool(*r.Refresh)
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f ExistsSource) WithContext(v context.Context) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document; use `_all` to fetch the first document matching the ID across all types.
//
func (f ExistsSource) WithDocumentType(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.DocumentType = v
}
}
// WithParent - the ID of the parent document.
//
func (f ExistsSource) WithParent(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Parent = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f ExistsSource) WithPreference(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Preference = v
}
}
// WithRealtime - specify whether to perform the operation in realtime or search mode.
//
func (f ExistsSource) WithRealtime(v bool) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Realtime = &v
}
}
// WithRefresh - refresh the shard containing the document before performing the operation.
//
func (f ExistsSource) WithRefresh(v bool) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Refresh = &v
}
}
// WithRouting - specific routing value.
//
func (f ExistsSource) WithRouting(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f ExistsSource) WithSource(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f ExistsSource) WithSourceExclude(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f ExistsSource) WithSourceInclude(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.SourceInclude = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f ExistsSource) WithVersion(v int) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f ExistsSource) WithVersionType(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.VersionType = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ExistsSource) WithPretty() func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ExistsSource) WithHuman() func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ExistsSource) WithErrorTrace() func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ExistsSource) WithFilterPath(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ExistsSource) WithHeader(h map[string]string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,374 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newExplainFunc(t Transport) Explain {
return func(index string, id string, o ...func(*ExplainRequest)) (*Response, error) {
var r = ExplainRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Explain returns information about why a specific matches (or doesn't match) a query.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-explain.html.
//
type Explain func(index string, id string, o ...func(*ExplainRequest)) (*Response, error)
// ExplainRequest configures the Explain API request.
//
type ExplainRequest struct {
Index string
DocumentType string
DocumentID string
Body io.Reader
Analyzer string
AnalyzeWildcard *bool
DefaultOperator string
Df string
Lenient *bool
Parent string
Preference string
Query string
Routing string
Source []string
SourceExclude []string
SourceInclude []string
StoredFields []string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r ExplainRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_explain"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_explain")
params = make(map[string]string)
if r.Analyzer != "" {
params["analyzer"] = r.Analyzer
}
if r.AnalyzeWildcard != nil {
params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard)
}
if r.DefaultOperator != "" {
params["default_operator"] = r.DefaultOperator
}
if r.Df != "" {
params["df"] = r.Df
}
if r.Lenient != nil {
params["lenient"] = strconv.FormatBool(*r.Lenient)
}
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Query != "" {
params["q"] = r.Query
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if len(r.StoredFields) > 0 {
params["stored_fields"] = strings.Join(r.StoredFields, ",")
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Explain) WithContext(v context.Context) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.ctx = v
}
}
// WithBody - The query definition using the Query DSL.
//
func (f Explain) WithBody(v io.Reader) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Body = v
}
}
// WithDocumentType - the type of the document.
//
func (f Explain) WithDocumentType(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.DocumentType = v
}
}
// WithAnalyzer - the analyzer for the query string query.
//
func (f Explain) WithAnalyzer(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Analyzer = v
}
}
// WithAnalyzeWildcard - specify whether wildcards and prefix queries in the query string query should be analyzed (default: false).
//
func (f Explain) WithAnalyzeWildcard(v bool) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.AnalyzeWildcard = &v
}
}
// WithDefaultOperator - the default operator for query string query (and or or).
//
func (f Explain) WithDefaultOperator(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.DefaultOperator = v
}
}
// WithDf - the default field for query string query (default: _all).
//
func (f Explain) WithDf(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Df = v
}
}
// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored.
//
func (f Explain) WithLenient(v bool) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Lenient = &v
}
}
// WithParent - the ID of the parent document.
//
func (f Explain) WithParent(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Parent = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f Explain) WithPreference(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Preference = v
}
}
// WithQuery - query in the lucene query string syntax.
//
func (f Explain) WithQuery(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Query = v
}
}
// WithRouting - specific routing value.
//
func (f Explain) WithRouting(v string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f Explain) WithSource(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f Explain) WithSourceExclude(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f Explain) WithSourceInclude(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.SourceInclude = v
}
}
// WithStoredFields - a list of stored fields to return in the response.
//
func (f Explain) WithStoredFields(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.StoredFields = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Explain) WithPretty() func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Explain) WithHuman() func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Explain) WithErrorTrace() func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Explain) WithFilterPath(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Explain) WithHeader(h map[string]string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,249 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newFieldCapsFunc(t Transport) FieldCaps {
return func(o ...func(*FieldCapsRequest)) (*Response, error) {
var r = FieldCapsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// FieldCaps returns the information about the capabilities of fields among multiple indices.
//
// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-caps.html.
//
type FieldCaps func(o ...func(*FieldCapsRequest)) (*Response, error)
// FieldCapsRequest configures the Field Caps API request.
//
type FieldCapsRequest struct {
Index []string
Body io.Reader
AllowNoIndices *bool
ExpandWildcards string
Fields []string
IgnoreUnavailable *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r FieldCapsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_field_caps"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_field_caps")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if len(r.Fields) > 0 {
params["fields"] = strings.Join(r.Fields, ",")
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f FieldCaps) WithContext(v context.Context) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.ctx = v
}
}
// WithBody - Field json objects containing an array of field names.
//
func (f FieldCaps) WithBody(v io.Reader) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.Body = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f FieldCaps) WithIndex(v ...string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f FieldCaps) WithAllowNoIndices(v bool) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f FieldCaps) WithExpandWildcards(v string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.ExpandWildcards = v
}
}
// WithFields - a list of field names.
//
func (f FieldCaps) WithFields(v ...string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.Fields = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f FieldCaps) WithIgnoreUnavailable(v bool) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f FieldCaps) WithPretty() func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f FieldCaps) WithHuman() func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f FieldCaps) WithErrorTrace() func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f FieldCaps) WithFilterPath(v ...string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f FieldCaps) WithHeader(h map[string]string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,261 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newFieldStatsFunc(t Transport) FieldStats {
return func(o ...func(*FieldStatsRequest)) (*Response, error) {
var r = FieldStatsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-stats.html.
//
type FieldStats func(o ...func(*FieldStatsRequest)) (*Response, error)
// FieldStatsRequest configures the Field Stats API request.
//
type FieldStatsRequest struct {
Index []string
Body io.Reader
AllowNoIndices *bool
ExpandWildcards string
Fields []string
IgnoreUnavailable *bool
Level string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r FieldStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_field_stats"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_field_stats")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if len(r.Fields) > 0 {
params["fields"] = strings.Join(r.Fields, ",")
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Level != "" {
params["level"] = r.Level
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f FieldStats) WithContext(v context.Context) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.ctx = v
}
}
// WithBody - Field json objects containing the name and optionally a range to filter out indices result, that have results outside the defined bounds.
//
func (f FieldStats) WithBody(v io.Reader) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Body = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f FieldStats) WithIndex(v ...string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f FieldStats) WithAllowNoIndices(v bool) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f FieldStats) WithExpandWildcards(v string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.ExpandWildcards = v
}
}
// WithFields - a list of fields for to get field statistics for (min value, max value, and more).
//
func (f FieldStats) WithFields(v ...string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Fields = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f FieldStats) WithIgnoreUnavailable(v bool) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLevel - defines if field stats should be returned on a per index level or on a cluster wide level.
//
func (f FieldStats) WithLevel(v string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Level = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f FieldStats) WithPretty() func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f FieldStats) WithHuman() func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f FieldStats) WithErrorTrace() func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f FieldStats) WithFilterPath(v ...string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f FieldStats) WithHeader(h map[string]string) func(*FieldStatsRequest) {
return func(r *FieldStatsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,331 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newGetFunc(t Transport) Get {
return func(index string, id string, o ...func(*GetRequest)) (*Response, error) {
var r = GetRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Get returns a document.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html.
//
type Get func(index string, id string, o ...func(*GetRequest)) (*Response, error)
// GetRequest configures the Get API request.
//
type GetRequest struct {
Index string
DocumentType string
DocumentID string
Parent string
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExclude []string
SourceInclude []string
StoredFields []string
Version *int
VersionType string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r GetRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Realtime != nil {
params["realtime"] = strconv.FormatBool(*r.Realtime)
}
if r.Refresh != nil {
params["refresh"] = strconv.FormatBool(*r.Refresh)
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if len(r.StoredFields) > 0 {
params["stored_fields"] = strings.Join(r.StoredFields, ",")
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Get) WithContext(v context.Context) func(*GetRequest) {
return func(r *GetRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document (use `_all` to fetch the first document matching the ID across all types).
//
func (f Get) WithDocumentType(v string) func(*GetRequest) {
return func(r *GetRequest) {
r.DocumentType = v
}
}
// WithParent - the ID of the parent document.
//
func (f Get) WithParent(v string) func(*GetRequest) {
return func(r *GetRequest) {
r.Parent = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f Get) WithPreference(v string) func(*GetRequest) {
return func(r *GetRequest) {
r.Preference = v
}
}
// WithRealtime - specify whether to perform the operation in realtime or search mode.
//
func (f Get) WithRealtime(v bool) func(*GetRequest) {
return func(r *GetRequest) {
r.Realtime = &v
}
}
// WithRefresh - refresh the shard containing the document before performing the operation.
//
func (f Get) WithRefresh(v bool) func(*GetRequest) {
return func(r *GetRequest) {
r.Refresh = &v
}
}
// WithRouting - specific routing value.
//
func (f Get) WithRouting(v string) func(*GetRequest) {
return func(r *GetRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f Get) WithSource(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f Get) WithSourceExclude(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f Get) WithSourceInclude(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.SourceInclude = v
}
}
// WithStoredFields - a list of stored fields to return in the response.
//
func (f Get) WithStoredFields(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.StoredFields = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f Get) WithVersion(v int) func(*GetRequest) {
return func(r *GetRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f Get) WithVersionType(v string) func(*GetRequest) {
return func(r *GetRequest) {
r.VersionType = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Get) WithPretty() func(*GetRequest) {
return func(r *GetRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Get) WithHuman() func(*GetRequest) {
return func(r *GetRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Get) WithErrorTrace() func(*GetRequest) {
return func(r *GetRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Get) WithFilterPath(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Get) WithHeader(h map[string]string) func(*GetRequest) {
return func(r *GetRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,174 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
)
func newGetScriptFunc(t Transport) GetScript {
return func(id string, lang string, o ...func(*GetScriptRequest)) (*Response, error) {
var r = GetScriptRequest{ScriptID: id, Lang: lang}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// GetScript returns a script.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting.html.
//
type GetScript func(id string, lang string, o ...func(*GetScriptRequest)) (*Response, error)
// GetScriptRequest configures the Get Script API request.
//
type GetScriptRequest struct {
ScriptID string
Lang string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r GetScriptRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_scripts") + 1 + len(r.Lang) + 1 + len(r.ScriptID))
path.WriteString("/")
path.WriteString("_scripts")
path.WriteString("/")
path.WriteString(r.Lang)
path.WriteString("/")
path.WriteString(r.ScriptID)
params = make(map[string]string)
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f GetScript) WithContext(v context.Context) func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f GetScript) WithPretty() func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f GetScript) WithHuman() func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f GetScript) WithErrorTrace() func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f GetScript) WithFilterPath(v ...string) func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f GetScript) WithHeader(h map[string]string) func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,320 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newGetSourceFunc(t Transport) GetSource {
return func(index string, id string, o ...func(*GetSourceRequest)) (*Response, error) {
var r = GetSourceRequest{Index: index, DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// GetSource returns the source of a document.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html.
//
type GetSource func(index string, id string, o ...func(*GetSourceRequest)) (*Response, error)
// GetSourceRequest configures the Get Source API request.
//
type GetSourceRequest struct {
Index string
DocumentType string
DocumentID string
Parent string
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExclude []string
SourceInclude []string
Version *int
VersionType string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r GetSourceRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_source"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_source")
params = make(map[string]string)
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Preference != "" {
params["preference"] = r.Preference
}
if r.Realtime != nil {
params["realtime"] = strconv.FormatBool(*r.Realtime)
}
if r.Refresh != nil {
params["refresh"] = strconv.FormatBool(*r.Refresh)
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExclude) > 0 {
params["_source_exclude"] = strings.Join(r.SourceExclude, ",")
}
if len(r.SourceInclude) > 0 {
params["_source_include"] = strings.Join(r.SourceInclude, ",")
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f GetSource) WithContext(v context.Context) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.ctx = v
}
}
// WithDocumentType - the type of the document; use `_all` to fetch the first document matching the ID across all types.
//
func (f GetSource) WithDocumentType(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.DocumentType = v
}
}
// WithParent - the ID of the parent document.
//
func (f GetSource) WithParent(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Parent = v
}
}
// WithPreference - specify the node or shard the operation should be performed on (default: random).
//
func (f GetSource) WithPreference(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Preference = v
}
}
// WithRealtime - specify whether to perform the operation in realtime or search mode.
//
func (f GetSource) WithRealtime(v bool) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Realtime = &v
}
}
// WithRefresh - refresh the shard containing the document before performing the operation.
//
func (f GetSource) WithRefresh(v bool) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Refresh = &v
}
}
// WithRouting - specific routing value.
//
func (f GetSource) WithRouting(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Routing = v
}
}
// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f GetSource) WithSource(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Source = v
}
}
// WithSourceExclude - a list of fields to exclude from the returned _source field.
//
func (f GetSource) WithSourceExclude(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.SourceExclude = v
}
}
// WithSourceInclude - a list of fields to extract and return from the _source field.
//
func (f GetSource) WithSourceInclude(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.SourceInclude = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f GetSource) WithVersion(v int) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f GetSource) WithVersionType(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.VersionType = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f GetSource) WithPretty() func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f GetSource) WithHuman() func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f GetSource) WithErrorTrace() func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f GetSource) WithFilterPath(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f GetSource) WithHeader(h map[string]string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,171 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
)
func newGetTemplateFunc(t Transport) GetTemplate {
return func(id string, o ...func(*GetTemplateRequest)) (*Response, error) {
var r = GetTemplateRequest{DocumentID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-template.html.
//
type GetTemplate func(id string, o ...func(*GetTemplateRequest)) (*Response, error)
// GetTemplateRequest configures the Get Template API request.
//
type GetTemplateRequest struct {
DocumentID string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r GetTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_search") + 1 + len("template") + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString("_search")
path.WriteString("/")
path.WriteString("template")
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f GetTemplate) WithContext(v context.Context) func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f GetTemplate) WithPretty() func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f GetTemplate) WithHuman() func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f GetTemplate) WithErrorTrace() func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f GetTemplate) WithFilterPath(v ...string) func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f GetTemplate) WithHeader(h map[string]string) func(*GetTemplateRequest) {
return func(r *GetTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,353 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndexFunc(t Transport) Index {
return func(index string, body io.Reader, o ...func(*IndexRequest)) (*Response, error) {
var r = IndexRequest{Index: index, Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// Index creates or updates a document in an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-index_.html.
//
type Index func(index string, body io.Reader, o ...func(*IndexRequest)) (*Response, error)
// IndexRequest configures the Index API request.
//
type IndexRequest struct {
Index string
DocumentType string
DocumentID string
Body io.Reader
OpType string
Parent string
Pipeline string
Refresh string
Routing string
Timeout time.Duration
Timestamp time.Duration
TTL time.Duration
Version *int
VersionType string
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndexRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
if r.DocumentID != "" {
method = "PUT"
} else {
method = "POST"
}
if r.DocumentType == "" {
r.DocumentType = "_doc"
}
path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString(r.DocumentType)
if r.DocumentID != "" {
path.WriteString("/")
path.WriteString(r.DocumentID)
}
params = make(map[string]string)
if r.OpType != "" {
params["op_type"] = r.OpType
}
if r.Parent != "" {
params["parent"] = r.Parent
}
if r.Pipeline != "" {
params["pipeline"] = r.Pipeline
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Timestamp != 0 {
params["timestamp"] = formatDuration(r.Timestamp)
}
if r.TTL != 0 {
params["ttl"] = formatDuration(r.TTL)
}
if r.Version != nil {
params["version"] = strconv.FormatInt(int64(*r.Version), 10)
}
if r.VersionType != "" {
params["version_type"] = r.VersionType
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f Index) WithContext(v context.Context) func(*IndexRequest) {
return func(r *IndexRequest) {
r.ctx = v
}
}
// WithDocumentID - document ID.
//
func (f Index) WithDocumentID(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.DocumentID = v
}
}
// WithDocumentType - the type of the document.
//
func (f Index) WithDocumentType(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.DocumentType = v
}
}
// WithOpType - explicit operation type.
//
func (f Index) WithOpType(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.OpType = v
}
}
// WithParent - ID of the parent document.
//
func (f Index) WithParent(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Parent = v
}
}
// WithPipeline - the pipeline ID to preprocess incoming documents with.
//
func (f Index) WithPipeline(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Pipeline = v
}
}
// WithRefresh - if `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes..
//
func (f Index) WithRefresh(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Refresh = v
}
}
// WithRouting - specific routing value.
//
func (f Index) WithRouting(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Routing = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f Index) WithTimeout(v time.Duration) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Timeout = v
}
}
// WithTimestamp - explicit timestamp for the document.
//
func (f Index) WithTimestamp(v time.Duration) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Timestamp = v
}
}
// WithTTL - expiration time for the document.
//
func (f Index) WithTTL(v time.Duration) func(*IndexRequest) {
return func(r *IndexRequest) {
r.TTL = v
}
}
// WithVersion - explicit version number for concurrency control.
//
func (f Index) WithVersion(v int) func(*IndexRequest) {
return func(r *IndexRequest) {
r.Version = &v
}
}
// WithVersionType - specific version type.
//
func (f Index) WithVersionType(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.VersionType = v
}
}
// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the index operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1).
//
func (f Index) WithWaitForActiveShards(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f Index) WithPretty() func(*IndexRequest) {
return func(r *IndexRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f Index) WithHuman() func(*IndexRequest) {
return func(r *IndexRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Index) WithErrorTrace() func(*IndexRequest) {
return func(r *IndexRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f Index) WithFilterPath(v ...string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f Index) WithHeader(h map[string]string) func(*IndexRequest) {
return func(r *IndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,331 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
)
func newIndicesAnalyzeFunc(t Transport) IndicesAnalyze {
return func(o ...func(*IndicesAnalyzeRequest)) (*Response, error) {
var r = IndicesAnalyzeRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesAnalyze performs the analysis process on a text and return the tokens breakdown of the text.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-analyze.html.
//
type IndicesAnalyze func(o ...func(*IndicesAnalyzeRequest)) (*Response, error)
// IndicesAnalyzeRequest configures the Indices Analyze API request.
//
type IndicesAnalyzeRequest struct {
Index string
Body io.Reader
Analyzer string
Attributes []string
CharFilter []string
Explain *bool
Field string
Filter []string
Format string
PreferLocal *bool
Text []string
Tokenizer string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesAnalyzeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(r.Index) + 1 + len("_analyze"))
if r.Index != "" {
path.WriteString("/")
path.WriteString(r.Index)
}
path.WriteString("/")
path.WriteString("_analyze")
params = make(map[string]string)
if r.Analyzer != "" {
params["analyzer"] = r.Analyzer
}
if len(r.Attributes) > 0 {
params["attributes"] = strings.Join(r.Attributes, ",")
}
if len(r.CharFilter) > 0 {
params["char_filter"] = strings.Join(r.CharFilter, ",")
}
if r.Explain != nil {
params["explain"] = strconv.FormatBool(*r.Explain)
}
if r.Field != "" {
params["field"] = r.Field
}
if len(r.Filter) > 0 {
params["filter"] = strings.Join(r.Filter, ",")
}
if r.Format != "" {
params["format"] = r.Format
}
if r.Index != "" {
params["index"] = r.Index
}
if r.PreferLocal != nil {
params["prefer_local"] = strconv.FormatBool(*r.PreferLocal)
}
if len(r.Text) > 0 {
params["text"] = strings.Join(r.Text, ",")
}
if r.Tokenizer != "" {
params["tokenizer"] = r.Tokenizer
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesAnalyze) WithContext(v context.Context) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.ctx = v
}
}
// WithBody - The text on which the analysis should be performed.
//
func (f IndicesAnalyze) WithBody(v io.Reader) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Body = v
}
}
// WithIndex - the name of the index to scope the operation.
//
func (f IndicesAnalyze) WithIndex(v string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Index = v
}
}
// WithAnalyzer - the name of the analyzer to use.
//
func (f IndicesAnalyze) WithAnalyzer(v string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Analyzer = v
}
}
// WithAttributes - a list of token attributes to output, this parameter works only with `explain=true`.
//
func (f IndicesAnalyze) WithAttributes(v ...string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Attributes = v
}
}
// WithCharFilter - a list of character filters to use for the analysis.
//
func (f IndicesAnalyze) WithCharFilter(v ...string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.CharFilter = v
}
}
// WithExplain - with `true`, outputs more advanced details. (default: false).
//
func (f IndicesAnalyze) WithExplain(v bool) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Explain = &v
}
}
// WithField - use the analyzer configured for this field (instead of passing the analyzer name).
//
func (f IndicesAnalyze) WithField(v string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Field = v
}
}
// WithFilter - a list of filters to use for the analysis.
//
func (f IndicesAnalyze) WithFilter(v ...string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Filter = v
}
}
// WithFormat - format of the output.
//
func (f IndicesAnalyze) WithFormat(v string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Format = v
}
}
// WithPreferLocal - with `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true).
//
func (f IndicesAnalyze) WithPreferLocal(v bool) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.PreferLocal = &v
}
}
// WithText - the text on which the analysis should be performed (when request body is not used).
//
func (f IndicesAnalyze) WithText(v ...string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Text = v
}
}
// WithTokenizer - the name of the tokenizer to use for the analysis.
//
func (f IndicesAnalyze) WithTokenizer(v string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Tokenizer = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesAnalyze) WithPretty() func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesAnalyze) WithHuman() func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesAnalyze) WithErrorTrace() func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesAnalyze) WithFilterPath(v ...string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesAnalyze) WithHeader(h map[string]string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,318 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesClearCacheFunc(t Transport) IndicesClearCache {
return func(o ...func(*IndicesClearCacheRequest)) (*Response, error) {
var r = IndicesClearCacheRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesClearCache clears all or specific caches for one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-clearcache.html.
//
type IndicesClearCache func(o ...func(*IndicesClearCacheRequest)) (*Response, error)
// IndicesClearCacheRequest configures the Indices Clear Cache API request.
//
type IndicesClearCacheRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
Fielddata *bool
FieldData *bool
Fields []string
IgnoreUnavailable *bool
Query *bool
Recycler *bool
Request *bool
RequestCache *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesClearCacheRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_cache") + 1 + len("clear"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_cache")
path.WriteString("/")
path.WriteString("clear")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.Fielddata != nil {
params["fielddata"] = strconv.FormatBool(*r.Fielddata)
}
if r.FieldData != nil {
params["field_data"] = strconv.FormatBool(*r.FieldData)
}
if len(r.Fields) > 0 {
params["fields"] = strings.Join(r.Fields, ",")
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if len(r.Index) > 0 {
params["index"] = strings.Join(r.Index, ",")
}
if r.Query != nil {
params["query"] = strconv.FormatBool(*r.Query)
}
if r.Recycler != nil {
params["recycler"] = strconv.FormatBool(*r.Recycler)
}
if r.Request != nil {
params["request"] = strconv.FormatBool(*r.Request)
}
if r.RequestCache != nil {
params["request_cache"] = strconv.FormatBool(*r.RequestCache)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesClearCache) WithContext(v context.Context) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.ctx = v
}
}
// WithIndex - a list of index name to limit the operation.
//
func (f IndicesClearCache) WithIndex(v ...string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesClearCache) WithAllowNoIndices(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesClearCache) WithExpandWildcards(v string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.ExpandWildcards = v
}
}
// WithFielddata - clear field data.
//
func (f IndicesClearCache) WithFielddata(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Fielddata = &v
}
}
// WithFieldData - clear field data.
//
func (f IndicesClearCache) WithFieldData(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.FieldData = &v
}
}
// WithFields - a list of fields to clear when using the `field_data` parameter (default: all).
//
func (f IndicesClearCache) WithFields(v ...string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Fields = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesClearCache) WithIgnoreUnavailable(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.IgnoreUnavailable = &v
}
}
// WithQuery - clear query caches.
//
func (f IndicesClearCache) WithQuery(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Query = &v
}
}
// WithRecycler - clear the recycler cache.
//
func (f IndicesClearCache) WithRecycler(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Recycler = &v
}
}
// WithRequest - clear request cache.
//
func (f IndicesClearCache) WithRequest(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Request = &v
}
}
// WithRequestCache - clear request cache.
//
func (f IndicesClearCache) WithRequestCache(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.RequestCache = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesClearCache) WithPretty() func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesClearCache) WithHuman() func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesClearCache) WithErrorTrace() func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesClearCache) WithFilterPath(v ...string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesClearCache) WithHeader(h map[string]string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,238 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesCloseFunc(t Transport) IndicesClose {
return func(index []string, o ...func(*IndicesCloseRequest)) (*Response, error) {
var r = IndicesCloseRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesClose closes an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-open-close.html.
//
type IndicesClose func(index []string, o ...func(*IndicesCloseRequest)) (*Response, error)
// IndicesCloseRequest configures the Indices Close API request.
//
type IndicesCloseRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesCloseRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_close"))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_close")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesClose) WithContext(v context.Context) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.ctx = v
}
}
// WithAllowNoIndices - 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 (f IndicesClose) WithAllowNoIndices(v bool) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesClose) WithExpandWildcards(v string) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesClose) WithIgnoreUnavailable(v bool) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesClose) WithMasterTimeout(v time.Duration) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesClose) WithTimeout(v time.Duration) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesClose) WithPretty() func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesClose) WithHuman() func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesClose) WithErrorTrace() func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesClose) WithFilterPath(v ...string) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesClose) WithHeader(h map[string]string) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,238 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesCreateFunc(t Transport) IndicesCreate {
return func(index string, o ...func(*IndicesCreateRequest)) (*Response, error) {
var r = IndicesCreateRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesCreate creates an index with optional settings and mappings.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-create-index.html.
//
type IndicesCreate func(index string, o ...func(*IndicesCreateRequest)) (*Response, error)
// IndicesCreateRequest configures the Indices Create API request.
//
type IndicesCreateRequest struct {
Index string
Body io.Reader
MasterTimeout time.Duration
Timeout time.Duration
UpdateAllTypes *bool
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesCreateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len(r.Index))
path.WriteString("/")
path.WriteString(r.Index)
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.UpdateAllTypes != nil {
params["update_all_types"] = strconv.FormatBool(*r.UpdateAllTypes)
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesCreate) WithContext(v context.Context) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.ctx = v
}
}
// WithBody - The configuration for the index (`settings` and `mappings`).
//
func (f IndicesCreate) WithBody(v io.Reader) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.Body = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesCreate) WithMasterTimeout(v time.Duration) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesCreate) WithTimeout(v time.Duration) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.Timeout = v
}
}
// WithUpdateAllTypes - whether to update the mapping for all fields with the same name across all types or not.
//
func (f IndicesCreate) WithUpdateAllTypes(v bool) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.UpdateAllTypes = &v
}
}
// WithWaitForActiveShards - set the number of active shards to wait for before the operation returns..
//
func (f IndicesCreate) WithWaitForActiveShards(v string) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesCreate) WithPretty() func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesCreate) WithHuman() func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesCreate) WithErrorTrace() func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesCreate) WithFilterPath(v ...string) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesCreate) WithHeader(h map[string]string) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,196 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
"time"
)
func newIndicesDeleteFunc(t Transport) IndicesDelete {
return func(index []string, o ...func(*IndicesDeleteRequest)) (*Response, error) {
var r = IndicesDeleteRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesDelete deletes an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-delete-index.html.
//
type IndicesDelete func(index []string, o ...func(*IndicesDeleteRequest)) (*Response, error)
// IndicesDeleteRequest configures the Indices Delete API request.
//
type IndicesDeleteRequest struct {
Index []string
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesDeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesDelete) WithContext(v context.Context) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesDelete) WithMasterTimeout(v time.Duration) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesDelete) WithTimeout(v time.Duration) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesDelete) WithPretty() func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesDelete) WithHuman() func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesDelete) WithErrorTrace() func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesDelete) WithFilterPath(v ...string) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesDelete) WithHeader(h map[string]string) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,202 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
"time"
)
func newIndicesDeleteAliasFunc(t Transport) IndicesDeleteAlias {
return func(index []string, name []string, o ...func(*IndicesDeleteAliasRequest)) (*Response, error) {
var r = IndicesDeleteAliasRequest{Index: index, Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesDeleteAlias deletes an alias.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html.
//
type IndicesDeleteAlias func(index []string, name []string, o ...func(*IndicesDeleteAliasRequest)) (*Response, error)
// IndicesDeleteAliasRequest configures the Indices Delete Alias API request.
//
type IndicesDeleteAliasRequest struct {
Index []string
Name []string
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesDeleteAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_aliases") + 1 + len(strings.Join(r.Name, ",")))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_aliases")
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesDeleteAlias) WithContext(v context.Context) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesDeleteAlias) WithMasterTimeout(v time.Duration) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit timestamp for the document.
//
func (f IndicesDeleteAlias) WithTimeout(v time.Duration) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesDeleteAlias) WithPretty() func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesDeleteAlias) WithHuman() func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesDeleteAlias) WithErrorTrace() func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesDeleteAlias) WithFilterPath(v ...string) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesDeleteAlias) WithHeader(h map[string]string) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,198 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strings"
"time"
)
func newIndicesDeleteTemplateFunc(t Transport) IndicesDeleteTemplate {
return func(name string, o ...func(*IndicesDeleteTemplateRequest)) (*Response, error) {
var r = IndicesDeleteTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesDeleteTemplate deletes an index template.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html.
//
type IndicesDeleteTemplate func(name string, o ...func(*IndicesDeleteTemplateRequest)) (*Response, error)
// IndicesDeleteTemplateRequest configures the Indices Delete Template API request.
//
type IndicesDeleteTemplateRequest struct {
Name string
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesDeleteTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_template")
path.WriteString("/")
path.WriteString(r.Name)
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesDeleteTemplate) WithContext(v context.Context) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesDeleteTemplate) WithMasterTimeout(v time.Duration) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesDeleteTemplate) WithTimeout(v time.Duration) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesDeleteTemplate) WithPretty() func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesDeleteTemplate) WithHuman() func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesDeleteTemplate) WithErrorTrace() func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesDeleteTemplate) WithFilterPath(v ...string) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesDeleteTemplate) WithHeader(h map[string]string) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,248 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesExistsFunc(t Transport) IndicesExists {
return func(index []string, o ...func(*IndicesExistsRequest)) (*Response, error) {
var r = IndicesExistsRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExists returns information about whether a particular index exists.
//
// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-exists.html.
//
type IndicesExists func(index []string, o ...func(*IndicesExistsRequest)) (*Response, error)
// IndicesExistsRequest configures the Indices Exists API request.
//
type IndicesExistsRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
FlatSettings *bool
IgnoreUnavailable *bool
IncludeDefaults *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesExistsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len(strings.Join(r.Index, ",")))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.IncludeDefaults != nil {
params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesExists) WithContext(v context.Context) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.ctx = v
}
}
// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false).
//
func (f IndicesExists) WithAllowNoIndices(v bool) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open).
//
func (f IndicesExists) WithExpandWildcards(v string) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.ExpandWildcards = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesExists) WithFlatSettings(v bool) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.FlatSettings = &v
}
}
// WithIgnoreUnavailable - ignore unavailable indexes (default: false).
//
func (f IndicesExists) WithIgnoreUnavailable(v bool) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithIncludeDefaults - whether to return all default setting for each of the indices..
//
func (f IndicesExists) WithIncludeDefaults(v bool) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.IncludeDefaults = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesExists) WithLocal(v bool) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesExists) WithPretty() func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesExists) WithHuman() func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesExists) WithErrorTrace() func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesExists) WithFilterPath(v ...string) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesExists) WithHeader(h map[string]string) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,248 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesExistsAliasFunc(t Transport) IndicesExistsAlias {
return func(o ...func(*IndicesExistsAliasRequest)) (*Response, error) {
var r = IndicesExistsAliasRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExistsAlias returns information about whether a particular alias exists.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html.
//
type IndicesExistsAlias func(o ...func(*IndicesExistsAliasRequest)) (*Response, error)
// IndicesExistsAliasRequest configures the Indices Exists Alias API request.
//
type IndicesExistsAliasRequest struct {
Index []string
Name []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesExistsAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ",")))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_alias")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesExistsAlias) WithContext(v context.Context) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to filter aliases.
//
func (f IndicesExistsAlias) WithIndex(v ...string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.Index = v
}
}
// WithName - a list of alias names to return.
//
func (f IndicesExistsAlias) WithName(v ...string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.Name = v
}
}
// WithAllowNoIndices - 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 (f IndicesExistsAlias) WithAllowNoIndices(v bool) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesExistsAlias) WithExpandWildcards(v string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesExistsAlias) WithIgnoreUnavailable(v bool) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesExistsAlias) WithLocal(v bool) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesExistsAlias) WithPretty() func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesExistsAlias) WithHuman() func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesExistsAlias) WithErrorTrace() func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesExistsAlias) WithFilterPath(v ...string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesExistsAlias) WithHeader(h map[string]string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,212 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesExistsTemplateFunc(t Transport) IndicesExistsTemplate {
return func(name []string, o ...func(*IndicesExistsTemplateRequest)) (*Response, error) {
var r = IndicesExistsTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExistsTemplate returns information about whether a particular index template exists.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html.
//
type IndicesExistsTemplate func(name []string, o ...func(*IndicesExistsTemplateRequest)) (*Response, error)
// IndicesExistsTemplateRequest configures the Indices Exists Template API request.
//
type IndicesExistsTemplateRequest struct {
Name []string
FlatSettings *bool
Local *bool
MasterTimeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesExistsTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len("_template") + 1 + len(strings.Join(r.Name, ",")))
path.WriteString("/")
path.WriteString("_template")
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
params = make(map[string]string)
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesExistsTemplate) WithContext(v context.Context) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.ctx = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesExistsTemplate) WithFlatSettings(v bool) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.FlatSettings = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesExistsTemplate) WithLocal(v bool) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f IndicesExistsTemplate) WithMasterTimeout(v time.Duration) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesExistsTemplate) WithPretty() func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesExistsTemplate) WithHuman() func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesExistsTemplate) WithErrorTrace() func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesExistsTemplate) WithFilterPath(v ...string) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesExistsTemplate) WithHeader(h map[string]string) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,235 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesExistsDocumentTypeFunc(t Transport) IndicesExistsDocumentType {
return func(index []string, o ...func(*IndicesExistsDocumentTypeRequest)) (*Response, error) {
var r = IndicesExistsDocumentTypeRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExistsDocumentType returns information about whether a particular document type exists. (DEPRECATED)
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-types-exists.html.
//
type IndicesExistsDocumentType func(index []string, o ...func(*IndicesExistsDocumentTypeRequest)) (*Response, error)
// IndicesExistsDocumentTypeRequest configures the Indices Exists Document Type API request.
//
type IndicesExistsDocumentTypeRequest struct {
Index []string
DocumentType []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesExistsDocumentTypeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping") + 1 + len(strings.Join(r.DocumentType, ",")))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_mapping")
path.WriteString("/")
path.WriteString(strings.Join(r.DocumentType, ","))
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesExistsDocumentType) WithContext(v context.Context) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.ctx = v
}
}
// WithDocumentType - a list of document types to check.
//
func (f IndicesExistsDocumentType) WithDocumentType(v ...string) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f IndicesExistsDocumentType) WithAllowNoIndices(v bool) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesExistsDocumentType) WithExpandWildcards(v string) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesExistsDocumentType) WithIgnoreUnavailable(v bool) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesExistsDocumentType) WithLocal(v bool) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesExistsDocumentType) WithPretty() func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesExistsDocumentType) WithHuman() func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesExistsDocumentType) WithErrorTrace() func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesExistsDocumentType) WithFilterPath(v ...string) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesExistsDocumentType) WithHeader(h map[string]string) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,247 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesFlushFunc(t Transport) IndicesFlush {
return func(o ...func(*IndicesFlushRequest)) (*Response, error) {
var r = IndicesFlushRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesFlush performs the flush operation on one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-flush.html.
//
type IndicesFlush func(o ...func(*IndicesFlushRequest)) (*Response, error)
// IndicesFlushRequest configures the Indices Flush API request.
//
type IndicesFlushRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
Force *bool
IgnoreUnavailable *bool
WaitIfOngoing *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesFlushRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_flush"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_flush")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.Force != nil {
params["force"] = strconv.FormatBool(*r.Force)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.WaitIfOngoing != nil {
params["wait_if_ongoing"] = strconv.FormatBool(*r.WaitIfOngoing)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesFlush) WithContext(v context.Context) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all for all indices.
//
func (f IndicesFlush) WithIndex(v ...string) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesFlush) WithAllowNoIndices(v bool) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesFlush) WithExpandWildcards(v string) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.ExpandWildcards = v
}
}
// WithForce - whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. this is useful if transaction log ids should be incremented even if no uncommitted changes are present. (this setting can be considered as internal).
//
func (f IndicesFlush) WithForce(v bool) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.Force = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesFlush) WithIgnoreUnavailable(v bool) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.IgnoreUnavailable = &v
}
}
// WithWaitIfOngoing - if set to true the flush operation will block until the flush can be executed if another flush operation is already executing. the default is true. if set to false the flush will be skipped iff if another flush operation is already running..
//
func (f IndicesFlush) WithWaitIfOngoing(v bool) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.WaitIfOngoing = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesFlush) WithPretty() func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesFlush) WithHuman() func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesFlush) WithErrorTrace() func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesFlush) WithFilterPath(v ...string) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesFlush) WithHeader(h map[string]string) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,223 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesFlushSyncedFunc(t Transport) IndicesFlushSynced {
return func(o ...func(*IndicesFlushSyncedRequest)) (*Response, error) {
var r = IndicesFlushSyncedRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesFlushSynced performs a synced flush operation on one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-synced-flush.html.
//
type IndicesFlushSynced func(o ...func(*IndicesFlushSyncedRequest)) (*Response, error)
// IndicesFlushSyncedRequest configures the Indices Flush Synced API request.
//
type IndicesFlushSyncedRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesFlushSyncedRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_flush") + 1 + len("synced"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_flush")
path.WriteString("/")
path.WriteString("synced")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesFlushSynced) WithContext(v context.Context) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all for all indices.
//
func (f IndicesFlushSynced) WithIndex(v ...string) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesFlushSynced) WithAllowNoIndices(v bool) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesFlushSynced) WithExpandWildcards(v string) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesFlushSynced) WithIgnoreUnavailable(v bool) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesFlushSynced) WithPretty() func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesFlushSynced) WithHuman() func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesFlushSynced) WithErrorTrace() func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesFlushSynced) WithFilterPath(v ...string) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesFlushSynced) WithHeader(h map[string]string) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,287 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
)
func newIndicesForcemergeFunc(t Transport) IndicesForcemerge {
return func(o ...func(*IndicesForcemergeRequest)) (*Response, error) {
var r = IndicesForcemergeRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesForcemerge performs the force merge operation on one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-forcemerge.html.
//
type IndicesForcemerge func(o ...func(*IndicesForcemergeRequest)) (*Response, error)
// IndicesForcemergeRequest configures the Indices Forcemerge API request.
//
type IndicesForcemergeRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
Flush *bool
IgnoreUnavailable *bool
MaxNumSegments *int
OnlyExpungeDeletes *bool
OperationThreading interface{}
WaitForMerge *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesForcemergeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_forcemerge"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_forcemerge")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.Flush != nil {
params["flush"] = strconv.FormatBool(*r.Flush)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MaxNumSegments != nil {
params["max_num_segments"] = strconv.FormatInt(int64(*r.MaxNumSegments), 10)
}
if r.OnlyExpungeDeletes != nil {
params["only_expunge_deletes"] = strconv.FormatBool(*r.OnlyExpungeDeletes)
}
if r.OperationThreading != nil {
params["operation_threading"] = fmt.Sprintf("%v", r.OperationThreading)
}
if r.WaitForMerge != nil {
params["wait_for_merge"] = strconv.FormatBool(*r.WaitForMerge)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesForcemerge) WithContext(v context.Context) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesForcemerge) WithIndex(v ...string) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesForcemerge) WithAllowNoIndices(v bool) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesForcemerge) WithExpandWildcards(v string) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.ExpandWildcards = v
}
}
// WithFlush - specify whether the index should be flushed after performing the operation (default: true).
//
func (f IndicesForcemerge) WithFlush(v bool) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.Flush = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesForcemerge) WithIgnoreUnavailable(v bool) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMaxNumSegments - the number of segments the index should be merged into (default: dynamic).
//
func (f IndicesForcemerge) WithMaxNumSegments(v int) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.MaxNumSegments = &v
}
}
// WithOnlyExpungeDeletes - specify whether the operation should only expunge deleted documents.
//
func (f IndicesForcemerge) WithOnlyExpungeDeletes(v bool) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.OnlyExpungeDeletes = &v
}
}
// WithOperationThreading - todo: ?.
//
func (f IndicesForcemerge) WithOperationThreading(v interface{}) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.OperationThreading = v
}
}
// WithWaitForMerge - specify whether the request should block until the merge process is finished (default: true).
//
func (f IndicesForcemerge) WithWaitForMerge(v bool) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.WaitForMerge = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesForcemerge) WithPretty() func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesForcemerge) WithHuman() func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesForcemerge) WithErrorTrace() func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesForcemerge) WithFilterPath(v ...string) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesForcemerge) WithHeader(h map[string]string) func(*IndicesForcemergeRequest) {
return func(r *IndicesForcemergeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,262 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetFunc(t Transport) IndicesGet {
return func(index []string, o ...func(*IndicesGetRequest)) (*Response, error) {
var r = IndicesGetRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGet returns information about one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-index.html.
//
type IndicesGet func(index []string, o ...func(*IndicesGetRequest)) (*Response, error)
// IndicesGetRequest configures the Indices Get API request.
//
type IndicesGetRequest struct {
Index []string
Feature []string
AllowNoIndices *bool
ExpandWildcards string
FlatSettings *bool
IgnoreUnavailable *bool
IncludeDefaults *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len(strings.Join(r.Feature, ",")))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
if len(r.Feature) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Feature, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.IncludeDefaults != nil {
params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGet) WithContext(v context.Context) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.ctx = v
}
}
// WithFeature - a list of features.
//
func (f IndicesGet) WithFeature(v ...string) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.Feature = v
}
}
// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false).
//
func (f IndicesGet) WithAllowNoIndices(v bool) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open).
//
func (f IndicesGet) WithExpandWildcards(v string) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.ExpandWildcards = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesGet) WithFlatSettings(v bool) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.FlatSettings = &v
}
}
// WithIgnoreUnavailable - ignore unavailable indexes (default: false).
//
func (f IndicesGet) WithIgnoreUnavailable(v bool) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.IgnoreUnavailable = &v
}
}
// WithIncludeDefaults - whether to return all default setting for each of the indices..
//
func (f IndicesGet) WithIncludeDefaults(v bool) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.IncludeDefaults = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGet) WithLocal(v bool) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGet) WithPretty() func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGet) WithHuman() func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGet) WithErrorTrace() func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGet) WithFilterPath(v ...string) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGet) WithHeader(h map[string]string) func(*IndicesGetRequest) {
return func(r *IndicesGetRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,248 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetAliasFunc(t Transport) IndicesGetAlias {
return func(o ...func(*IndicesGetAliasRequest)) (*Response, error) {
var r = IndicesGetAliasRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetAlias returns an alias.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html.
//
type IndicesGetAlias func(o ...func(*IndicesGetAliasRequest)) (*Response, error)
// IndicesGetAliasRequest configures the Indices Get Alias API request.
//
type IndicesGetAliasRequest struct {
Index []string
Name []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ",")))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_alias")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetAlias) WithContext(v context.Context) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names to filter aliases.
//
func (f IndicesGetAlias) WithIndex(v ...string) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.Index = v
}
}
// WithName - a list of alias names to return.
//
func (f IndicesGetAlias) WithName(v ...string) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.Name = v
}
}
// WithAllowNoIndices - 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 (f IndicesGetAlias) WithAllowNoIndices(v bool) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesGetAlias) WithExpandWildcards(v string) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesGetAlias) WithIgnoreUnavailable(v bool) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGetAlias) WithLocal(v bool) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetAlias) WithPretty() func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetAlias) WithHuman() func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetAlias) WithErrorTrace() func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetAlias) WithFilterPath(v ...string) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetAlias) WithHeader(h map[string]string) func(*IndicesGetAliasRequest) {
return func(r *IndicesGetAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,266 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetFieldMappingFunc(t Transport) IndicesGetFieldMapping {
return func(fields []string, o ...func(*IndicesGetFieldMappingRequest)) (*Response, error) {
var r = IndicesGetFieldMappingRequest{Fields: fields}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetFieldMapping returns mapping for one or more fields.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-field-mapping.html.
//
type IndicesGetFieldMapping func(fields []string, o ...func(*IndicesGetFieldMappingRequest)) (*Response, error)
// IndicesGetFieldMappingRequest configures the Indices Get Field Mapping API request.
//
type IndicesGetFieldMappingRequest struct {
Index []string
DocumentType []string
Fields []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
IncludeDefaults *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetFieldMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping") + 1 + len(strings.Join(r.DocumentType, ",")) + 1 + len("field") + 1 + len(strings.Join(r.Fields, ",")))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_mapping")
if len(r.DocumentType) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.DocumentType, ","))
}
path.WriteString("/")
path.WriteString("field")
path.WriteString("/")
path.WriteString(strings.Join(r.Fields, ","))
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.IncludeDefaults != nil {
params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetFieldMapping) WithContext(v context.Context) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names.
//
func (f IndicesGetFieldMapping) WithIndex(v ...string) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.Index = v
}
}
// WithDocumentType - a list of document types.
//
func (f IndicesGetFieldMapping) WithDocumentType(v ...string) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f IndicesGetFieldMapping) WithAllowNoIndices(v bool) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesGetFieldMapping) WithExpandWildcards(v string) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesGetFieldMapping) WithIgnoreUnavailable(v bool) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.IgnoreUnavailable = &v
}
}
// WithIncludeDefaults - whether the default mapping values should be returned as well.
//
func (f IndicesGetFieldMapping) WithIncludeDefaults(v bool) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.IncludeDefaults = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGetFieldMapping) WithLocal(v bool) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetFieldMapping) WithPretty() func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetFieldMapping) WithHuman() func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetFieldMapping) WithErrorTrace() func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetFieldMapping) WithFilterPath(v ...string) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetFieldMapping) WithHeader(h map[string]string) func(*IndicesGetFieldMappingRequest) {
return func(r *IndicesGetFieldMappingRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,247 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetMappingFunc(t Transport) IndicesGetMapping {
return func(o ...func(*IndicesGetMappingRequest)) (*Response, error) {
var r = IndicesGetMappingRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetMapping returns mappings for one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-mapping.html.
//
type IndicesGetMapping func(o ...func(*IndicesGetMappingRequest)) (*Response, error)
// IndicesGetMappingRequest configures the Indices Get Mapping API request.
//
type IndicesGetMappingRequest struct {
Index []string
DocumentType []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping") + 1 + len(strings.Join(r.DocumentType, ",")))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_mapping")
if len(r.DocumentType) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.DocumentType, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetMapping) WithContext(v context.Context) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names.
//
func (f IndicesGetMapping) WithIndex(v ...string) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.Index = v
}
}
// WithDocumentType - a list of document types.
//
func (f IndicesGetMapping) WithDocumentType(v ...string) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f IndicesGetMapping) WithAllowNoIndices(v bool) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesGetMapping) WithExpandWildcards(v string) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesGetMapping) WithIgnoreUnavailable(v bool) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.IgnoreUnavailable = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGetMapping) WithLocal(v bool) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetMapping) WithPretty() func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetMapping) WithHuman() func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetMapping) WithErrorTrace() func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetMapping) WithFilterPath(v ...string) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetMapping) WithHeader(h map[string]string) func(*IndicesGetMappingRequest) {
return func(r *IndicesGetMappingRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,274 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetSettingsFunc(t Transport) IndicesGetSettings {
return func(o ...func(*IndicesGetSettingsRequest)) (*Response, error) {
var r = IndicesGetSettingsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetSettings returns settings for one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-settings.html.
//
type IndicesGetSettings func(o ...func(*IndicesGetSettingsRequest)) (*Response, error)
// IndicesGetSettingsRequest configures the Indices Get Settings API request.
//
type IndicesGetSettingsRequest struct {
Index []string
Name []string
AllowNoIndices *bool
ExpandWildcards string
FlatSettings *bool
IgnoreUnavailable *bool
IncludeDefaults *bool
Local *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings") + 1 + len(strings.Join(r.Name, ",")))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_settings")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.IncludeDefaults != nil {
params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetSettings) WithContext(v context.Context) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesGetSettings) WithIndex(v ...string) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.Index = v
}
}
// WithName - the name of the settings that should be included.
//
func (f IndicesGetSettings) WithName(v ...string) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.Name = v
}
}
// WithAllowNoIndices - 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 (f IndicesGetSettings) WithAllowNoIndices(v bool) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesGetSettings) WithExpandWildcards(v string) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.ExpandWildcards = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesGetSettings) WithFlatSettings(v bool) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.FlatSettings = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesGetSettings) WithIgnoreUnavailable(v bool) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithIncludeDefaults - whether to return all default setting for each of the indices..
//
func (f IndicesGetSettings) WithIncludeDefaults(v bool) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.IncludeDefaults = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGetSettings) WithLocal(v bool) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.Local = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetSettings) WithPretty() func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetSettings) WithHuman() func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetSettings) WithErrorTrace() func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetSettings) WithFilterPath(v ...string) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetSettings) WithHeader(h map[string]string) func(*IndicesGetSettingsRequest) {
return func(r *IndicesGetSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,222 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesGetTemplateFunc(t Transport) IndicesGetTemplate {
return func(o ...func(*IndicesGetTemplateRequest)) (*Response, error) {
var r = IndicesGetTemplateRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetTemplate returns an index template.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html.
//
type IndicesGetTemplate func(o ...func(*IndicesGetTemplateRequest)) (*Response, error)
// IndicesGetTemplateRequest configures the Indices Get Template API request.
//
type IndicesGetTemplateRequest struct {
Name []string
FlatSettings *bool
Local *bool
MasterTimeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_template") + 1 + len(strings.Join(r.Name, ",")))
path.WriteString("/")
path.WriteString("_template")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
params = make(map[string]string)
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.Local != nil {
params["local"] = strconv.FormatBool(*r.Local)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetTemplate) WithContext(v context.Context) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.ctx = v
}
}
// WithName - the comma separated names of the index templates.
//
func (f IndicesGetTemplate) WithName(v ...string) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.Name = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesGetTemplate) WithFlatSettings(v bool) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.FlatSettings = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesGetTemplate) WithLocal(v bool) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f IndicesGetTemplate) WithMasterTimeout(v time.Duration) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetTemplate) WithPretty() func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetTemplate) WithHuman() func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetTemplate) WithErrorTrace() func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetTemplate) WithFilterPath(v ...string) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetTemplate) WithHeader(h map[string]string) func(*IndicesGetTemplateRequest) {
return func(r *IndicesGetTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,221 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesGetUpgradeFunc(t Transport) IndicesGetUpgrade {
return func(o ...func(*IndicesGetUpgradeRequest)) (*Response, error) {
var r = IndicesGetUpgradeRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesGetUpgrade the _upgrade API is no longer useful and will be removed.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-upgrade.html.
//
type IndicesGetUpgrade func(o ...func(*IndicesGetUpgradeRequest)) (*Response, error)
// IndicesGetUpgradeRequest configures the Indices Get Upgrade API request.
//
type IndicesGetUpgradeRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesGetUpgradeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_upgrade"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_upgrade")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesGetUpgrade) WithContext(v context.Context) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesGetUpgrade) WithIndex(v ...string) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesGetUpgrade) WithAllowNoIndices(v bool) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesGetUpgrade) WithExpandWildcards(v string) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesGetUpgrade) WithIgnoreUnavailable(v bool) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesGetUpgrade) WithPretty() func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesGetUpgrade) WithHuman() func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesGetUpgrade) WithErrorTrace() func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesGetUpgrade) WithFilterPath(v ...string) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesGetUpgrade) WithHeader(h map[string]string) func(*IndicesGetUpgradeRequest) {
return func(r *IndicesGetUpgradeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,238 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesOpenFunc(t Transport) IndicesOpen {
return func(index []string, o ...func(*IndicesOpenRequest)) (*Response, error) {
var r = IndicesOpenRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesOpen opens an index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-open-close.html.
//
type IndicesOpen func(index []string, o ...func(*IndicesOpenRequest)) (*Response, error)
// IndicesOpenRequest configures the Indices Open API request.
//
type IndicesOpenRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesOpenRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_open"))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_open")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesOpen) WithContext(v context.Context) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.ctx = v
}
}
// WithAllowNoIndices - 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 (f IndicesOpen) WithAllowNoIndices(v bool) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesOpen) WithExpandWildcards(v string) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesOpen) WithIgnoreUnavailable(v bool) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesOpen) WithMasterTimeout(v time.Duration) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesOpen) WithTimeout(v time.Duration) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesOpen) WithPretty() func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesOpen) WithHuman() func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesOpen) WithErrorTrace() func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesOpen) WithFilterPath(v ...string) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesOpen) WithHeader(h map[string]string) func(*IndicesOpenRequest) {
return func(r *IndicesOpenRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,217 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strings"
"time"
)
func newIndicesPutAliasFunc(t Transport) IndicesPutAlias {
return func(index []string, name string, o ...func(*IndicesPutAliasRequest)) (*Response, error) {
var r = IndicesPutAliasRequest{Index: index, Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesPutAlias creates or updates an alias.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html.
//
type IndicesPutAlias func(index []string, name string, o ...func(*IndicesPutAliasRequest)) (*Response, error)
// IndicesPutAliasRequest configures the Indices Put Alias API request.
//
type IndicesPutAliasRequest struct {
Index []string
Body io.Reader
Name string
MasterTimeout time.Duration
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesPutAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_aliases") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_aliases")
path.WriteString("/")
path.WriteString(r.Name)
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesPutAlias) WithContext(v context.Context) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.ctx = v
}
}
// WithBody - The settings for the alias, such as `routing` or `filter`.
//
func (f IndicesPutAlias) WithBody(v io.Reader) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.Body = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesPutAlias) WithMasterTimeout(v time.Duration) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit timestamp for the document.
//
func (f IndicesPutAlias) WithTimeout(v time.Duration) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesPutAlias) WithPretty() func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesPutAlias) WithHuman() func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesPutAlias) WithErrorTrace() func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesPutAlias) WithFilterPath(v ...string) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesPutAlias) WithHeader(h map[string]string) func(*IndicesPutAliasRequest) {
return func(r *IndicesPutAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,281 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesPutMappingFunc(t Transport) IndicesPutMapping {
return func(body io.Reader, o ...func(*IndicesPutMappingRequest)) (*Response, error) {
var r = IndicesPutMappingRequest{Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesPutMapping updates the index mappings.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-put-mapping.html.
//
type IndicesPutMapping func(body io.Reader, o ...func(*IndicesPutMappingRequest)) (*Response, error)
// IndicesPutMappingRequest configures the Indices Put Mapping API request.
//
type IndicesPutMappingRequest struct {
Index []string
DocumentType string
Body io.Reader
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
MasterTimeout time.Duration
Timeout time.Duration
UpdateAllTypes *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesPutMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(len(strings.Join(r.Index, ",")) + len("/_mapping") + len(r.DocumentType) + 2)
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_mapping")
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.UpdateAllTypes != nil {
params["update_all_types"] = strconv.FormatBool(*r.UpdateAllTypes)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesPutMapping) WithContext(v context.Context) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices..
//
func (f IndicesPutMapping) WithIndex(v ...string) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.Index = v
}
}
// WithDocumentType - the name of the document type.
//
func (f IndicesPutMapping) WithDocumentType(v string) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.DocumentType = v
}
}
// WithAllowNoIndices - 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 (f IndicesPutMapping) WithAllowNoIndices(v bool) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesPutMapping) WithExpandWildcards(v string) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesPutMapping) WithIgnoreUnavailable(v bool) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesPutMapping) WithMasterTimeout(v time.Duration) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesPutMapping) WithTimeout(v time.Duration) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.Timeout = v
}
}
// WithUpdateAllTypes - whether to update the mapping for all fields with the same name across all types or not.
//
func (f IndicesPutMapping) WithUpdateAllTypes(v bool) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.UpdateAllTypes = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesPutMapping) WithPretty() func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesPutMapping) WithHuman() func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesPutMapping) WithErrorTrace() func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesPutMapping) WithFilterPath(v ...string) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesPutMapping) WithHeader(h map[string]string) func(*IndicesPutMappingRequest) {
return func(r *IndicesPutMappingRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,268 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesPutSettingsFunc(t Transport) IndicesPutSettings {
return func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error) {
var r = IndicesPutSettingsRequest{Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesPutSettings updates the index settings.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-update-settings.html.
//
type IndicesPutSettings func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error)
// IndicesPutSettingsRequest configures the Indices Put Settings API request.
//
type IndicesPutSettingsRequest struct {
Index []string
Body io.Reader
AllowNoIndices *bool
ExpandWildcards string
FlatSettings *bool
IgnoreUnavailable *bool
MasterTimeout time.Duration
PreserveExisting *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesPutSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_settings")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.PreserveExisting != nil {
params["preserve_existing"] = strconv.FormatBool(*r.PreserveExisting)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesPutSettings) WithContext(v context.Context) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesPutSettings) WithIndex(v ...string) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesPutSettings) WithAllowNoIndices(v bool) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesPutSettings) WithExpandWildcards(v string) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.ExpandWildcards = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesPutSettings) WithFlatSettings(v bool) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.FlatSettings = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesPutSettings) WithIgnoreUnavailable(v bool) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesPutSettings) WithMasterTimeout(v time.Duration) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.MasterTimeout = v
}
}
// WithPreserveExisting - whether to update existing settings. if set to `true` existing settings on an index remain unchanged, the default is `false`.
//
func (f IndicesPutSettings) WithPreserveExisting(v bool) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.PreserveExisting = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesPutSettings) WithPretty() func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesPutSettings) WithHuman() func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesPutSettings) WithErrorTrace() func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesPutSettings) WithFilterPath(v ...string) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesPutSettings) WithHeader(h map[string]string) func(*IndicesPutSettingsRequest) {
return func(r *IndicesPutSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,245 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesPutTemplateFunc(t Transport) IndicesPutTemplate {
return func(name string, body io.Reader, o ...func(*IndicesPutTemplateRequest)) (*Response, error) {
var r = IndicesPutTemplateRequest{Name: name, Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesPutTemplate creates or updates an index template.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html.
//
type IndicesPutTemplate func(name string, body io.Reader, o ...func(*IndicesPutTemplateRequest)) (*Response, error)
// IndicesPutTemplateRequest configures the Indices Put Template API request.
//
type IndicesPutTemplateRequest struct {
Body io.Reader
Name string
Create *bool
FlatSettings *bool
MasterTimeout time.Duration
Order *int
Timeout time.Duration
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesPutTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len("_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_template")
path.WriteString("/")
path.WriteString(r.Name)
params = make(map[string]string)
if r.Create != nil {
params["create"] = strconv.FormatBool(*r.Create)
}
if r.FlatSettings != nil {
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Order != nil {
params["order"] = strconv.FormatInt(int64(*r.Order), 10)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesPutTemplate) WithContext(v context.Context) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.ctx = v
}
}
// WithCreate - whether the index template should only be added if new or can also replace an existing one.
//
func (f IndicesPutTemplate) WithCreate(v bool) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.Create = &v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesPutTemplate) WithFlatSettings(v bool) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.FlatSettings = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesPutTemplate) WithMasterTimeout(v time.Duration) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.MasterTimeout = v
}
}
// WithOrder - the order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers).
//
func (f IndicesPutTemplate) WithOrder(v int) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.Order = &v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesPutTemplate) WithTimeout(v time.Duration) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesPutTemplate) WithPretty() func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesPutTemplate) WithHuman() func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesPutTemplate) WithErrorTrace() func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesPutTemplate) WithFilterPath(v ...string) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesPutTemplate) WithHeader(h map[string]string) func(*IndicesPutTemplateRequest) {
return func(r *IndicesPutTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,208 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesRecoveryFunc(t Transport) IndicesRecovery {
return func(o ...func(*IndicesRecoveryRequest)) (*Response, error) {
var r = IndicesRecoveryRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesRecovery returns information about ongoing index shard recoveries.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-recovery.html.
//
type IndicesRecovery func(o ...func(*IndicesRecoveryRequest)) (*Response, error)
// IndicesRecoveryRequest configures the Indices Recovery API request.
//
type IndicesRecoveryRequest struct {
Index []string
ActiveOnly *bool
Detailed *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesRecoveryRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_recovery"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_recovery")
params = make(map[string]string)
if r.ActiveOnly != nil {
params["active_only"] = strconv.FormatBool(*r.ActiveOnly)
}
if r.Detailed != nil {
params["detailed"] = strconv.FormatBool(*r.Detailed)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesRecovery) WithContext(v context.Context) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesRecovery) WithIndex(v ...string) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.Index = v
}
}
// WithActiveOnly - display only those recoveries that are currently on-going.
//
func (f IndicesRecovery) WithActiveOnly(v bool) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.ActiveOnly = &v
}
}
// WithDetailed - whether to display detailed information about shard recovery.
//
func (f IndicesRecovery) WithDetailed(v bool) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.Detailed = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesRecovery) WithPretty() func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesRecovery) WithHuman() func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesRecovery) WithErrorTrace() func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesRecovery) WithFilterPath(v ...string) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesRecovery) WithHeader(h map[string]string) func(*IndicesRecoveryRequest) {
return func(r *IndicesRecoveryRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,221 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesRefreshFunc(t Transport) IndicesRefresh {
return func(o ...func(*IndicesRefreshRequest)) (*Response, error) {
var r = IndicesRefreshRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesRefresh performs the refresh operation in one or more indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-refresh.html.
//
type IndicesRefresh func(o ...func(*IndicesRefreshRequest)) (*Response, error)
// IndicesRefreshRequest configures the Indices Refresh API request.
//
type IndicesRefreshRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesRefreshRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_refresh"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_refresh")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesRefresh) WithContext(v context.Context) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesRefresh) WithIndex(v ...string) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesRefresh) WithAllowNoIndices(v bool) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesRefresh) WithExpandWildcards(v string) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesRefresh) WithIgnoreUnavailable(v bool) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesRefresh) WithPretty() func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesRefresh) WithHuman() func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesRefresh) WithErrorTrace() func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesRefresh) WithFilterPath(v ...string) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesRefresh) WithHeader(h map[string]string) func(*IndicesRefreshRequest) {
return func(r *IndicesRefreshRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,254 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesRolloverFunc(t Transport) IndicesRollover {
return func(alias string, o ...func(*IndicesRolloverRequest)) (*Response, error) {
var r = IndicesRolloverRequest{Alias: alias}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesRollover updates an alias to point to a new index when the existing index
// is considered to be too large or too old.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-rollover-index.html.
//
type IndicesRollover func(alias string, o ...func(*IndicesRolloverRequest)) (*Response, error)
// IndicesRolloverRequest configures the Indices Rollover API request.
//
type IndicesRolloverRequest struct {
Body io.Reader
Alias string
NewIndex string
DryRun *bool
MasterTimeout time.Duration
Timeout time.Duration
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesRolloverRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len(r.Alias) + 1 + len("_rollover") + 1 + len(r.NewIndex))
path.WriteString("/")
path.WriteString(r.Alias)
path.WriteString("/")
path.WriteString("_rollover")
if r.NewIndex != "" {
path.WriteString("/")
path.WriteString(r.NewIndex)
}
params = make(map[string]string)
if r.DryRun != nil {
params["dry_run"] = strconv.FormatBool(*r.DryRun)
}
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesRollover) WithContext(v context.Context) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.ctx = v
}
}
// WithBody - The conditions that needs to be met for executing rollover.
//
func (f IndicesRollover) WithBody(v io.Reader) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.Body = v
}
}
// WithNewIndex - the name of the rollover index.
//
func (f IndicesRollover) WithNewIndex(v string) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.NewIndex = v
}
}
// WithDryRun - if set to true the rollover action will only be validated but not actually performed even if a condition matches. the default is false.
//
func (f IndicesRollover) WithDryRun(v bool) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.DryRun = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesRollover) WithMasterTimeout(v time.Duration) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesRollover) WithTimeout(v time.Duration) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.Timeout = v
}
}
// WithWaitForActiveShards - set the number of active shards to wait for on the newly created rollover index before the operation returns..
//
func (f IndicesRollover) WithWaitForActiveShards(v string) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesRollover) WithPretty() func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesRollover) WithHuman() func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesRollover) WithErrorTrace() func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesRollover) WithFilterPath(v ...string) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesRollover) WithHeader(h map[string]string) func(*IndicesRolloverRequest) {
return func(r *IndicesRolloverRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,248 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
)
func newIndicesSegmentsFunc(t Transport) IndicesSegments {
return func(o ...func(*IndicesSegmentsRequest)) (*Response, error) {
var r = IndicesSegmentsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesSegments provides low-level information about segments in a Lucene index.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-segments.html.
//
type IndicesSegments func(o ...func(*IndicesSegmentsRequest)) (*Response, error)
// IndicesSegmentsRequest configures the Indices Segments API request.
//
type IndicesSegmentsRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
OperationThreading interface{}
Verbose *bool
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesSegmentsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_segments"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_segments")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.OperationThreading != nil {
params["operation_threading"] = fmt.Sprintf("%v", r.OperationThreading)
}
if r.Verbose != nil {
params["verbose"] = strconv.FormatBool(*r.Verbose)
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesSegments) WithContext(v context.Context) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesSegments) WithIndex(v ...string) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesSegments) WithAllowNoIndices(v bool) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesSegments) WithExpandWildcards(v string) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesSegments) WithIgnoreUnavailable(v bool) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithOperationThreading - todo: ?.
//
func (f IndicesSegments) WithOperationThreading(v interface{}) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.OperationThreading = v
}
}
// WithVerbose - includes detailed memory usage by lucene..
//
func (f IndicesSegments) WithVerbose(v bool) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.Verbose = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesSegments) WithPretty() func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesSegments) WithHuman() func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesSegments) WithErrorTrace() func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesSegments) WithFilterPath(v ...string) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesSegments) WithHeader(h map[string]string) func(*IndicesSegmentsRequest) {
return func(r *IndicesSegmentsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,248 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
)
func newIndicesShardStoresFunc(t Transport) IndicesShardStores {
return func(o ...func(*IndicesShardStoresRequest)) (*Response, error) {
var r = IndicesShardStoresRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesShardStores provides store information for shard copies of indices.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-shards-stores.html.
//
type IndicesShardStores func(o ...func(*IndicesShardStoresRequest)) (*Response, error)
// IndicesShardStoresRequest configures the Indices Shard Stores API request.
//
type IndicesShardStoresRequest struct {
Index []string
AllowNoIndices *bool
ExpandWildcards string
IgnoreUnavailable *bool
OperationThreading interface{}
Status []string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesShardStoresRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_shard_stores"))
if len(r.Index) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
}
path.WriteString("/")
path.WriteString("_shard_stores")
params = make(map[string]string)
if r.AllowNoIndices != nil {
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
}
if r.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
if r.IgnoreUnavailable != nil {
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
}
if r.OperationThreading != nil {
params["operation_threading"] = fmt.Sprintf("%v", r.OperationThreading)
}
if len(r.Status) > 0 {
params["status"] = strings.Join(r.Status, ",")
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), nil)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesShardStores) WithContext(v context.Context) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.ctx = v
}
}
// WithIndex - a list of index names; use _all to perform the operation on all indices.
//
func (f IndicesShardStores) WithIndex(v ...string) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.Index = v
}
}
// WithAllowNoIndices - 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 (f IndicesShardStores) WithAllowNoIndices(v bool) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesShardStores) WithExpandWildcards(v string) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesShardStores) WithIgnoreUnavailable(v bool) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.IgnoreUnavailable = &v
}
}
// WithOperationThreading - todo: ?.
//
func (f IndicesShardStores) WithOperationThreading(v interface{}) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.OperationThreading = v
}
}
// WithStatus - a list of statuses used to filter on shards to get store information for.
//
func (f IndicesShardStores) WithStatus(v ...string) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.Status = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesShardStores) WithPretty() func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesShardStores) WithHuman() func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesShardStores) WithErrorTrace() func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesShardStores) WithFilterPath(v ...string) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesShardStores) WithHeader(h map[string]string) func(*IndicesShardStoresRequest) {
return func(r *IndicesShardStoresRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

View File

@@ -0,0 +1,230 @@
// Code generated from specification version 5.6.15: DO NOT EDIT
package esapi
import (
"context"
"io"
"net/http"
"strings"
"time"
)
func newIndicesShrinkFunc(t Transport) IndicesShrink {
return func(index string, target string, o ...func(*IndicesShrinkRequest)) (*Response, error) {
var r = IndicesShrinkRequest{Index: index, Target: target}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesShrink allow to shrink an existing index into a new index with fewer primary shards.
//
// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-shrink-index.html.
//
type IndicesShrink func(index string, target string, o ...func(*IndicesShrinkRequest)) (*Response, error)
// IndicesShrinkRequest configures the Indices Shrink API request.
//
type IndicesShrinkRequest struct {
Index string
Body io.Reader
Target string
MasterTimeout time.Duration
Timeout time.Duration
WaitForActiveShards string
Pretty bool
Human bool
ErrorTrace bool
FilterPath []string
Header http.Header
ctx context.Context
}
// Do executes the request and returns response or error.
//
func (r IndicesShrinkRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len(r.Index) + 1 + len("_shrink") + 1 + len(r.Target))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString("_shrink")
path.WriteString("/")
path.WriteString(r.Target)
params = make(map[string]string)
if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}
if r.Timeout != 0 {
params["timeout"] = formatDuration(r.Timeout)
}
if r.WaitForActiveShards != "" {
params["wait_for_active_shards"] = r.WaitForActiveShards
}
if r.Pretty {
params["pretty"] = "true"
}
if r.Human {
params["human"] = "true"
}
if r.ErrorTrace {
params["error_trace"] = "true"
}
if len(r.FilterPath) > 0 {
params["filter_path"] = strings.Join(r.FilterPath, ",")
}
req, _ := newRequest(method, path.String(), r.Body)
if len(params) > 0 {
q := req.URL.Query()
for k, v := range params {
q.Set(k, v)
}
req.URL.RawQuery = q.Encode()
}
if r.Body != nil {
req.Header[headerContentType] = headerContentTypeJSON
}
if len(r.Header) > 0 {
if len(req.Header) == 0 {
req.Header = r.Header
} else {
for k, vv := range r.Header {
for _, v := range vv {
req.Header.Add(k, v)
}
}
}
}
if ctx != nil {
req = req.WithContext(ctx)
}
res, err := transport.Perform(req)
if err != nil {
return nil, err
}
response := Response{
StatusCode: res.StatusCode,
Body: res.Body,
Header: res.Header,
}
return &response, nil
}
// WithContext sets the request context.
//
func (f IndicesShrink) WithContext(v context.Context) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.ctx = v
}
}
// WithBody - The configuration for the target index (`settings` and `aliases`).
//
func (f IndicesShrink) WithBody(v io.Reader) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.Body = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesShrink) WithMasterTimeout(v time.Duration) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesShrink) WithTimeout(v time.Duration) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.Timeout = v
}
}
// WithWaitForActiveShards - set the number of active shards to wait for on the shrunken index before the operation returns..
//
func (f IndicesShrink) WithWaitForActiveShards(v string) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesShrink) WithPretty() func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesShrink) WithHuman() func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesShrink) WithErrorTrace() func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesShrink) WithFilterPath(v ...string) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesShrink) WithHeader(h map[string]string) func(*IndicesShrinkRequest) {
return func(r *IndicesShrinkRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}

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