intergrate opensearch v1 (#5135)

opensearchv1

Signed-off-by: chengdehao <dehaocheng@kubesphere.io>

Signed-off-by: chengdehao <dehaocheng@kubesphere.io>
Co-authored-by: chengdehao <dehaocheng@kubesphere.io>
This commit is contained in:
Elon Cheng
2022-08-12 06:58:33 -05:00
committed by GitHub
parent 2a31867df1
commit f741bc7943
186 changed files with 47471 additions and 4 deletions

5
go.mod
View File

@@ -33,7 +33,7 @@ require (
github.com/go-ldap/ldap v3.0.3+incompatible
github.com/go-logr/logr v0.4.0
github.com/go-openapi/loads v0.19.5
github.com/go-openapi/spec v0.19.7
github.com/go-openapi/spec v0.19.8
github.com/go-openapi/strfmt v0.19.5
github.com/go-openapi/validate v0.19.8
github.com/go-redis/redis v6.15.2+incompatible
@@ -55,6 +55,7 @@ require (
github.com/onsi/gomega v1.15.0
github.com/open-policy-agent/opa v0.18.0
github.com/opencontainers/go-digest v1.0.0
github.com/opensearch-project/opensearch-go v1.1.0
github.com/opensearch-project/opensearch-go/v2 v2.0.0
github.com/operator-framework/helm-operator-plugins v0.0.8-0.20210810182245-240cc447b3de
github.com/pkg/errors v0.9.1
@@ -64,7 +65,7 @@ require (
github.com/prometheus-operator/prometheus-operator v0.42.2-0.20200928114327-fbd01683839a
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.42.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.26.0
github.com/prometheus/common v0.37.0
github.com/prometheus/prometheus v1.8.2-0.20200907175821-8219b442c864
github.com/sony/sonyflake v0.0.0-20181109022403-6d5bd6181009
github.com/speps/go-hashids v2.0.0+incompatible

2
go.sum
View File

@@ -651,6 +651,8 @@ github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVo
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y=
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opensearch-project/opensearch-go v1.1.0 h1:eG5sh3843bbU1itPRjA9QXbxcg8LaZ+DjEzQH9aLN3M=
github.com/opensearch-project/opensearch-go v1.1.0/go.mod h1:+6/XHCuTH+fwsMJikZEWsucZ4eZMma3zNSeLrTtVGbo=
github.com/opensearch-project/opensearch-go/v2 v2.0.0 h1:Ij3CpuHwey29cYPVMgi5h1pWBH2O0JaTXsa4c7pqhK4=
github.com/opensearch-project/opensearch-go/v2 v2.0.0/go.mod h1:G3kbnV+SeVf4QTbNcrT7Ga3FCsavtp5NQfdRelJikIQ=
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02/go.mod h1:JNdpVEzCpXBgIiv4ds+TzhN1hrtxq6ClLrTlT9OQRSc=

View File

@@ -27,6 +27,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/es/query"
"kubesphere.io/kubesphere/pkg/simple/client/es/versions"
v1 "kubesphere.io/kubesphere/pkg/simple/client/es/versions/opensearchv1"
v2 "kubesphere.io/kubesphere/pkg/simple/client/es/versions/opensearchv2"
v5 "kubesphere.io/kubesphere/pkg/simple/client/es/versions/v5"
v6 "kubesphere.io/kubesphere/pkg/simple/client/es/versions/v6"
@@ -38,6 +39,7 @@ const (
ElasticV5 = "5"
ElasticV6 = "6"
ElasticV7 = "7"
OpenSearchV1 = "opensearchv1"
OpenSearchV2 = "opensearchv2"
)
@@ -66,6 +68,8 @@ func NewClient(host string, basicAuth bool, username, password, indexPrefix, ver
}
switch es.version {
case OpenSearchV1:
es.c, err = v1.New(es.host, es.basicAuth, es.username, es.password, es.index)
case OpenSearchV2:
es.c, err = v2.New(es.host, es.basicAuth, es.username, es.password, es.index)
case ElasticV5:
@@ -139,6 +143,8 @@ func (c *Client) loadClient() error {
v = "opensearchv" + v
}
switch v {
case OpenSearchV1:
vc, err = v1.New(c.host, c.basicAuth, c.username, c.password, c.index)
case OpenSearchV2:
vc, err = v2.New(c.host, c.basicAuth, c.username, c.password, c.index)
case ElasticV5:

View File

@@ -0,0 +1,128 @@
/*
Copyright 2020 KubeSphere Authors
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.
*/
package v1
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/opensearch-project/opensearch-go"
"github.com/opensearch-project/opensearch-go/opensearchapi"
"kubesphere.io/kubesphere/pkg/simple/client/es/versions"
)
type OpenSearch struct {
client *opensearch.Client
index string
}
func New(address string, basicAuth bool, username, password, index string) (*OpenSearch, error) {
var client *opensearch.Client
var err error
if !basicAuth {
username = ""
password = ""
}
client, err = opensearch.NewClient(opensearch.Config{
Addresses: []string{address},
Username: username,
Password: password,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
})
return &OpenSearch{client: client, index: index}, err
}
func (o *OpenSearch) Search(indices string, body []byte, scroll bool) ([]byte, error) {
opts := []func(*opensearchapi.SearchRequest){
o.client.Search.WithContext(context.Background()),
o.client.Search.WithIndex(indices),
o.client.Search.WithIgnoreUnavailable(true),
o.client.Search.WithBody(bytes.NewBuffer(body)),
}
if scroll {
opts = append(opts, o.client.Search.WithScroll(time.Minute))
}
response, err := o.client.Search(opts...)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.IsError() {
return nil, parseError(response)
}
return ioutil.ReadAll(response.Body)
}
func (o *OpenSearch) Scroll(id string) ([]byte, error) {
response, err := o.client.Scroll(
o.client.Scroll.WithContext(context.Background()),
o.client.Scroll.WithScrollID(id),
o.client.Scroll.WithScroll(time.Minute))
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.IsError() {
return nil, parseError(response)
}
return ioutil.ReadAll(response.Body)
}
func (o *OpenSearch) ClearScroll(scrollId string) {
response, _ := o.client.ClearScroll(
o.client.ClearScroll.WithContext(context.Background()),
o.client.ClearScroll.WithScrollID(scrollId))
defer response.Body.Close()
}
func (o *OpenSearch) GetTotalHitCount(v interface{}) int64 {
f, _ := v.(float64)
return int64(f)
}
func parseError(response *opensearchapi.Response) error {
var e versions.Error
if err := json.NewDecoder(response.Body).Decode(&e); err != nil {
return err
} else {
// Print the response status and error information.
if len(e.Details.RootCause) != 0 {
return fmt.Errorf("type: %v, reason: %v", e.Details.Type, e.Details.RootCause[0].Reason)
} else {
return fmt.Errorf("type: %v, reason: %v", e.Details.Type, e.Details.Reason)
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,5 @@
tmp/
*.test
#jetBrains editors
.idea

View File

@@ -0,0 +1,15 @@
{
"scanSettings": {
"configMode": "AUTO",
"configExternalURL": "",
"projectToken": "",
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}

View File

@@ -0,0 +1,31 @@
## Overview
This document explains who the admins are (see below), what they do in this repo, and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
## Current Admins
| Admin | GitHub ID | Affiliation |
| -------------------------| --------------------------------------- | ----------- |
| Charlotte | [CEHENKLE](https://github.com/CEHENKLE) | Amazon |
| Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon |
| Jack Mazanec | [jmazanec15](https://github.com/jmazanec15) | Amazon |
| Vamshi Vijay Nakkirtha | [vamshin](https://github.com/vamshin) | Amazon |
| Vijayan Balasubramanian | [VijayanB](https://github.com/VijayanB) | Amazon |
## Admin Responsibilities
As an admin you own stewartship of the repository and its settings. Admins have [admin-level permissions on a repository](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization). Use those privileges to serve the community and protect the repository as follows.
### Prioritize Security
Security is your number one priority. Manage security keys and safeguard access to the repository.
Note that this repository is monitored and supported 24/7 by Amazon Security, see [Reporting a Vulnerability](SECURITY.md) for details.
### Enforce Code of Conduct
Act on [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) violations by revoking access, and blocking malicious actors.
### Adopt Organizational Best Practices
Adopt organizational best practices, work in the open, and collaborate with other admins by opening issues before making process changes. Prefer consistency, and avoid diverging from practices in the opensearch-project organization.

View File

@@ -0,0 +1,25 @@
This code of conduct applies to all spaces provided by the OpenSource project including in code, documentation, issue trackers, mailing lists, chat channels, wikis, blogs, social media and any other communication channels used by the project.
**Our open source communities endeavor to:**
* Be Inclusive: We are committed to being a community where everyone can join and contribute. This means using inclusive and welcoming language.
* Be Welcoming: We are committed to maintaining a safe space for everyone to be able to contribute.
* Be Respectful: We are committed to encouraging differing viewpoints, accepting constructive criticism and work collaboratively towards decisions that help the project grow. Disrespectful and unacceptable behavior will not be tolerated.
* Be Collaborative: We are committed to supporting what is best for our community and users. When we build anything for the benefit of the project, we should document the work we do and communicate to others on how this affects their work.
**Our Responsibility. As contributors, members, or bystanders we each individually have the responsibility to behave professionally and respectfully at all times. Disrespectful and unacceptable behaviors include, but are not limited to:**
* The use of violent threats, abusive, discriminatory, or derogatory language;
* Offensive comments related to gender, gender identity and expression, sexual orientation, disability, mental illness, race, political or religious affiliation;
* Posting of sexually explicit or violent content;
* The use of sexualized language and unwelcome sexual attention or advances;
* Public or private harassment of any kind;
* Publishing private information, such as physical or electronic address, without permission;
* Other conduct which could reasonably be considered inappropriate in a professional setting;
* Advocating for or encouraging any of the above behaviors.
* Enforcement and Reporting Code of Conduct Issues:
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported. [Contact us](mailto:opensource-codeofconduct@amazon.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances.

View File

@@ -0,0 +1,96 @@
- [Contributing to OpenSearch](#contributing-to-opensearch)
- [First Things First](#first-things-first)
- [Ways to Contribute](#ways-to-contribute)
- [Bug Reports](#bug-reports)
- [Feature Requests](#feature-requests)
- [Contributing Code](#contributing-code)
- [Developer Certificate of Origin](#developer-certificate-of-origin)
- [Review Process](#review-process)
## Contributing to OpenSearch
OpenSearch is a community project that is built and maintained by people just like **you**. We're glad you're interested in helping out. There are several different ways you can do it, but before we talk about that, let's talk about how to get started.
## First Things First
1. **When in doubt, open an issue** - For almost any type of contribution, the first step is opening an issue. Even if you think you already know what the solution is, writing down a description of the problem you're trying to solve will help everyone get context when they review your pull request. If it's truly a trivial change (e.g. spelling error), you can skip this step -- but as the subject says, when it doubt, [open an issue](https://github.com/opensearch-project/opensearch-go/issues/new/choose).
2. **Only submit your own work** (or work you have sufficient rights to submit) - Please make sure that any code or documentation you submit is your work or you have the rights to submit. We respect the intellectual property rights of others, and as part of contributing, we'll ask you to sign your contribution with a "Developer Certificate of Origin" (DCO) that states you have the rights to submit this work and you understand we'll use your contribution. There's more information about this topic in the [DCO section](#developer-certificate-of-origin).
## Ways to Contribute
### Bug Reports
Ugh! Bugs!
A bug is when software behaves in a way that you didn't expect and the developer didn't intend. To help us understand what's going on, we first want to make sure you're working from the latest version.
Once you've confirmed that the bug still exists in the latest version, you'll want to check to make sure it's not something we already know about on the [open issues GitHub page](https://github.com/opensearch-project/opensearch-go/issues/new/choose).
If you've upgraded to the latest version and you can't find it in our open issues list, then you'll need to tell us how to reproduce it Provide as much information as you can. You may think that the problem lies with your query, when actually it depends on how your data is indexed. The easier it is for us to recreate your problem, the faster it is likely to be fixed.
### Feature Requests
If you've thought of a way that OpenSearch could be better, we want to hear about it. We track feature requests using GitHub, so please feel free to open an issue which describes the feature you would like to see, why you need it, and how it should work.
### Contributing Code
As with other types of contributions, the first step is to [open an issue on GitHub](https://github.com/opensearch-project/opensearch-go/issues/new/choose). Opening an issue before you make changes makes sure that someone else isn't already working on that particular problem. It also lets us all work together to find the right approach before you spend a bunch of time on a PR. So again, when in doubt, open an issue.
## Developer Certificate of Origin
OpenSearch is an open source product released under the Apache 2.0 license (see either [the Apache site](https://www.apache.org/licenses/LICENSE-2.0) or the [LICENSE.txt file](LICENSE.txt)). The Apache 2.0 license allows you to freely use, modify, distribute, and sell your own products that include Apache 2.0 licensed software.
We respect intellectual property rights of others and we want to make sure all incoming contributions are correctly attributed and licensed. A Developer Certificate of Origin (DCO) is a lightweight mechanism to do that.
The DCO is a declaration attached to every contribution made by every developer. In the commit message of the contribution, the developer simply adds a `Signed-off-by` statement and thereby agrees to the DCO, which you can find below or at [DeveloperCertificate.org](http://developercertificate.org/).
```
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the
best of my knowledge, is covered under an appropriate open
source license and I have the right under that license to
submit that work with modifications, whether created in whole
or in part by me, under the same open source license (unless
I am permitted to submit under a different license), as
Indicated in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including
all personal information I submit with it, including my
sign-off) is maintained indefinitely and may be redistributed
consistent with this project or the open source license(s)
involved.
```
We require that every contribution to OpenSearch is signed with a Developer Certificate of Origin. Additionally, please use your real name. We do not accept anonymous contributors nor those utilizing pseudonyms.
Each commit must include a DCO which looks like this
```
Signed-off-by: Jane Smith <jane.smith@email.com>
```
You may type this line on your own when writing your commit messages. However, if your user.name and user.email are set in your git configs, you can use `-s` or ` signoff` to add the `Signed-off-by` line to the end of the commit message.
## Review Process
We deeply appreciate everyone who takes the time to make a contribution. We will review all contributions as quickly as possible. As a reminder, [opening an issue](https://github.com/opensearch-project/opensearch-go/issues/new/choose) discussing your change before you make it is the best way to smooth the PR process. This will prevent a rejection because someone else is already working on the problem, or because the solution is incompatible with the architectural direction.
During the PR process, expect that there will be some back-and-forth. Please try to respond to comments in a timely fashion, and if you don't wish to continue with the PR, let us know. If a PR takes too many iterations for its complexity or size, we may reject it. Additionally, if you stop responding we may close the PR as abandoned. In either case, if you feel this was done in error, please add a comment on the PR.
If we accept the PR, a [maintainer](MAINTAINERS.md) will merge your change and usually take care of backporting it to appropriate branches ourselves.
If we reject the PR, we will close the pull request with a comment explaining why. This decision isn't always final: if you feel we have misunderstood your intended change or otherwise think that we should reconsider then please continue the conversation with a comment on the PR and we'll do our best to address any further points you raise.

View File

@@ -0,0 +1,65 @@
# Developer Guide
So you want to contribute code to the OpenSearch Go Client? Excellent! We're glad you're here. Here's what you need to do:
## Getting Started
### Git Clone OpenSearch Go Client Repository
Fork [opensearch-project/opensearch-go](https://github.com/opensearch-project/opensearch-go) and clone locally,
e.g. `git clone https://github.com/[your username]/opensearch-go.git`.
### Install Prerequisites
#### Go 1.11
OpenSearch Go Client builds using [Go](https://golang.org/doc/install) 1.11 at a minimum.
#### Docker
[Docker](https://docs.docker.com/install/) is required for building some OpenSearch artifacts and executing integration tests.
### Unit Testing
Go has a simple tool for running tests, and we simplified it further by creating this make command:
```
make test-unit
```
Individual unit tests can be run with the following command:
```
cd folder-path/to/test;
go test -v -run TestName;
```
### Integration Testing
In order to test opensearch-go client, you need a running OpenSearch cluster. You can use Docker to accomplish this.
The [Docker Compose file](.ci/opensearch/docker-compose.yml) supports the ability to run integration tests for the project in local environments.
If you have not installed docker-compose, you can install it from this [link](https://docs.docker.com/compose/install/).
In order to differentiate unit tests from integration tests, Go has a built-in mechanism for allowing you to logically separate your tests
with [build tags](https://pkg.go.dev/cmd/go#hdr-Build_constraints). The build tag needs to be placed as close to the top of the file as possible, and must have a blank line beneath it.
Hence, create all integration tests with build tag 'integration'.
#### Execute integration tests from your terminal
1. Run below command to start containers. By default, it will launch latest OpenSearch cluster.
```
make cluster.opensearch.build cluster.opensearch.start
```
2. Run all integration tests.
```
make test-integ race=true
```
3. Stop and clean containers.
```
make cluster.opensearch.stop cluster.clean
```
## Use an Editor
### GoLand
You can import the OpenSearch project into GoLand as follows:
1. Select **File | Open**
2. In the subsequent dialog navigate to the ~/go/src/opensearch-go and click **Open**
After you have opened your project, you need to specify the location of the Go SDK.
You can either specify a local path to the SDK or download it. To set the Go SDK, navigate to **Go | GOROOT** and
set accordingly.

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 [yyyy] [name of copyright owner]
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.

View File

@@ -0,0 +1,70 @@
- [Overview](#overview)
- [Current Maintainers](#current-maintainers)
- [Maintainer Responsibilities](#maintainer-responsibilities)
- [Uphold Code of Conduct](#uphold-code-of-conduct)
- [Prioritize Security](#prioritize-security)
- [Review Pull Requests](#review-pull-requests)
- [Triage Open Issues](#triage-open-issues)
- [Be Responsive](#be-responsive)
- [Maintain Overall Health of the Repo](#maintain-overall-health-of-the-repo)
- [Use Semver](#use-semver)
- [Release Frequently](#release-frequently)
- [Promote Other Maintainers](#promote-other-maintainers)
## Overview
This document explains who the maintainers are (see below), what they do in this repo, and how they should be doing it. If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
## Current Maintainers
| Maintainer | GitHub ID | Affiliation |
| ------------------------ | --------------------------------------- | ----------- |
| Jack Mazanec | [jmazanec15](https://github.com/jmazanec15) | Amazon |
| Vamshi Vijay Nakkirtha | [vamshin](https://github.com/vamshin) | Amazon |
| Vijayan Balasubramanian | [VijayanB](https://github.com/VijayanB) | Amazon |
## Maintainer Responsibilities
Maintainers are active and visible members of the community, and have [maintain-level permissions on a repository](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization). Use those privileges to serve the community and evolve code as follows.
### Uphold Code of Conduct
Model the behavior set forward by the [Code of Conduct](CODE_OF_CONDUCT.md) and raise any violations to other maintainers and admins.
### Prioritize Security
Security is your number one priority. Maintainer's Github keys must be password protected securely and any reported security vulnerabilities are addressed before features or bugs.
Note that this repository is monitored and supported 24/7 by Amazon Security, see [Reporting a Vulnerability](SECURITY.md) for details.
### Review Pull Requests
Review pull requests regularly, comment, suggest, reject, merge and close. Accept only high quality pull-requests. Provide code reviews and guidance on incomming pull requests. Don't let PRs be stale and do your best to be helpful to contributors.
### Triage Open Issues
Manage labels, review issues regularly, and triage by labelling them.
All repositories in this organization have a standard set of labels, including `bug`, `documentation`, `duplicate`, `enhancement`, `good first issue`, `help wanted`, `blocker`, `invalid`, `question`, `wontfix`, and `untriaged`, along with release labels, such as `v1.0.0`, `v1.1.0` and `v2.0.0`, and `backport`.
Use labels to target an issue or a PR for a given release, add `help wanted` to good issues for new community members, and `blocker` for issues that scare you or need immediate attention. Request for more information from a submitter if an issue is not clear. Create new labels as needed by the project.
### Be Responsive
Respond to enhancement requests, and forum posts. Allocate time to reviewing and commenting on issues and conversations as they come in.
### Maintain Overall Health of the Repo
Keep the `main` branch at production quality at all times. Backport features as needed. Cut release branches and tags to enable future patches.
### Use Semver
Use and enforce [semantic versioning](https://semver.org/) and do not let breaking changes be made outside of major releases.
### Release Frequently
Make frequent project releases to the community.
### Promote Other Maintainers
Assist, add, and remove [MAINTAINERS](MAINTAINERS.md). Exercise good judgement, and propose high quality contributors to become co-maintainers.

View File

@@ -0,0 +1,212 @@
SHELL := /bin/bash
##@ Format project using goimports tool
format:
goimports -w .;
##@ Test
test-unit: ## Run unit tests
@printf "\033[2m→ Running unit tests...\033[0m\n"
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
@printf "\033[2m→ Running integration tests...\033[0m\n"
$(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) "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \
else \
echo "go test -v" $(testintegargs) "."; \
go test -v $(testintegargs) "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \
fi;
test-integ-secure: ##Run secure integration tests
go test -tags=secure,integration ./opensearch_secure_integration_test.go
test-bench: ## Run benchmarks
@printf "\033[2m→ Running benchmarks...\033[0m\n"
go test -run=none -bench=. -benchmem ./...
test-coverage: ## Generate test coverage report
@printf "\033[2m→ Generating test coverage report...\033[0m\n"
@go tool cover -html=tmp/unit.cov -o tmp/coverage.html
@go tool cover -func=tmp/unit.cov | 'grep' -v 'opensearchapi/api\.' | sed 's/github.com\/opensearch-project\/opensearch-go\///g'
@printf "\033[0m--------------------------------------------------------------------------------\nopen tmp/coverage.html\n\n\033[0m"
##@ Development
lint: ## Run lint on the package
@printf "\033[2m→ Running lint...\033[0m\n"
go vet github.com/opensearch-project/opensearch-go/...
go list github.com/opensearch-project/opensearch-go/... | 'grep' -v internal | xargs golint -set_exit_status
@{ \
set -e ; \
trap "test -d ../../../.git && git checkout --quiet go.mod" INT TERM EXIT; \
echo "cd internal/build/ && go vet ./..."; \
cd "internal/build/" && go mod tidy && go mod download && go vet ./...; \
}
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 = '1.x')
else
$(eval branches_list = $(shell echo $(branches) | tr ',' ' ') )
endif
$(eval commits_list = $(shell echo $(commits) | tr ',' ' '))
@printf "\033[2m→ Backporting commits [$(commits)]\033[0m\n"
@{ \
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 \
printf "\033[2m→ $$branch\033[0m\n"; \
git checkout $$branch; \
for commit in $(commits_list); do \
git cherry-pick -x $$commit; \
done; \
git status --short --branch; \
echo ""; \
done; \
printf "\033[2m→ Push updates to Github:\033[0m\n"; \
for branch in $(branches_list); do \
echo "git push --verbose origin $$branch"; \
done; \
}
release: ## Release a new version to Github
$(eval branch = $(shell git rev-parse --abbrev-ref HEAD))
$(eval current_version = $(shell cat internal/version/version.go | sed -Ee 's/const Client = "(.*)"/\1/' | tail -1))
@printf "\033[2m→ [$(branch)] Current version: $(current_version)...\033[0m\n"
ifndef version
@printf "\033[31m[!] Missing version argument, exiting...\033[0m\n"
@exit 2
endif
ifeq ($(version), "")
@printf "\033[31m[!] Empty version argument, exiting...\033[0m\n"
@exit 2
endif
@printf "\033[2m→ [$(branch)] Creating version $(version)...\033[0m\n"
@{ \
set -e -o pipefail; \
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 && \
go vet internal/version/version.go && \
go fmt internal/version/version.go && \
git diff --color-words internal/version/version.go | tail -n 1; \
}
@{ \
set -e -o pipefail; \
printf "\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)'; \
printf "\033[2mPush `git show --pretty='%h (%s)' --no-patch HEAD` to Github:\033[0m\n\n"; \
printf "\033[1m git push origin HEAD && git push origin v$(version)\033[0m\n\n"; \
mv internal/version/version.go.OLD internal/version/version.go && \
git add internal/version/version.go && \
original_version=`cat internal/version/version.go | sed -ne 's;^const Client = "\(.*\)"$$;\1;p'` && \
git commit --no-status --quiet --message "Update version to $$original_version"; \
printf "\033[2mVersion updated to [$$original_version].\033[0m\n\n"; \
else \
echo "Aborting..."; \
rm internal/version/version.go.OLD; \
exit 1; \
fi; \
}
godoc: ## Display documentation for the package
@printf "\033[2m→ Generating documentation...\033[0m\n"
@echo "* http://localhost:6060/pkg/github.com/opensearch-project/opensearch-go"
@echo "* http://localhost:6060/pkg/github.com/opensearch-project/opensearch-go/opensearchapi"
@echo "* http://localhost:6060/pkg/github.com/opensearch-project/opensearch-go/opensearchtransport"
@echo "* http://localhost:6060/pkg/github.com/opensearch-project/opensearch-go/opensearchutil"
@printf "\n"
godoc --http=localhost:6060 --play
cluster.opendistro.build:
docker-compose --project-directory .ci/opendistro build;
cluster.opendistro.start:
docker-compose --project-directory .ci/opendistro up -d ;
sleep 20;
cluster.opendistro.stop:
docker-compose --project-directory .ci/opendistro down ;
cluster.opensearch.build:
docker-compose --project-directory .ci/opensearch build;
cluster.opensearch.start:
docker-compose --project-directory .ci/opensearch up -d ;
sleep 20;
cluster.opensearch.stop:
docker-compose --project-directory .ci/opensearch down ;
cluster.clean: ## Remove unused Docker volumes and networks
@printf "\033[2m→ Cleaning up Docker assets...\033[0m\n"
docker volume prune --force
docker network prune --force
docker system prune --volumes --force
workflow: ## Run all github workflow commands here sequentially
# Lint
make lint
# License Checker
.github/check-license-headers.sh
# Unit Test
make test-unit race=true
# Benchmarks Test
make test-bench
# Integration Test
### OpenDistro
make cluster.clean cluster.opendistro.build cluster.opendistro.start
make test-integ race=true
make cluster.opendistro.stop
### OpenSearch
make cluster.clean cluster.opensearch.build cluster.opensearch.start
make test-integ race=true
make cluster.opensearch.stop
##@ 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 backport cluster cluster.opendistro.build cluster.opendistro.start cluster.opendistro.stop cluster.clean coverage godoc lint release test test-bench test-integ test-unit

View File

@@ -0,0 +1,8 @@
OpenSearch (https://opensearch.org/)
Copyright 2021 OpenSearch Contributors
This product includes software developed by
Elasticsearch (http://www.elastic.co).
This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).

View File

@@ -0,0 +1 @@
<svg viewBox="0 0 372 72" height="64" fill="none" xmlns="http://www.w3.org/2000/svg"><style>.a{fill:#005EB8}.b{fill:#003B5C}@media(prefers-color-scheme:dark){.a{fill:#00A3E0}.b{fill:#B9D9EB}}</style><g class="a"><path d="M61.74 26.5a2.26 2.26 0 00-2.27 2.26 33.71 33.71 0 01-33.7 33.71 2.26 2.26 0 100 4.53A38.24 38.24 0 0064 28.76a2.26 2.26 0 00-2.26-2.26zM3.92 17A24.43 24.43 0 00.05 31.9c.86 13.73 13.3 24.14 25.03 23.02 4.6-.45 9.31-4.2 8.9-10.9-.19-2.92-1.62-4.64-3.93-5.96C27.84 36.8 25 36 21.79 35.1c-3.89-1.1-8.4-2.32-11.85-4.87-4.15-3.06-6.99-6.6-6.02-13.23z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M107.78 48.26c3.15-4.49 4.72-10.92 4.72-19.28 0-8.36-1.56-14.77-4.69-19.24C104.7 5.24 100.2 3 94.34 3 88.4 3 83.87 5.23 80.72 9.7 77.57 14.15 76 20.55 76 28.91c0 8.43 1.57 14.9 4.72 19.39 3.15 4.47 7.67 6.7 13.55 6.7 5.86 0 10.36-2.25 13.5-6.74zm-19.94-6.11c-1.46-3.02-2.19-7.4-2.19-13.17 0-5.78.73-10.17 2.2-13.16 1.45-3.02 3.62-4.53 6.49-4.53 5.65 0 8.47 5.9 8.47 17.7 0 11.79-2.85 17.68-8.54 17.68-2.83 0-4.97-1.5-6.43-4.52zM128.2 54c1.28.74 2.66 1 4.31 1 3.53 0 6.4-1.67 8.44-5.24C142.98 46.2 144 41.28 144 35c0-6.36-.99-11.28-2.96-14.76-1.97-3.5-4.7-5.24-8.18-5.24-3.62 0-6.46 2.16-8.36 6h-.5l-1.5-5h-7v55.5h9V55c0-.65-.13-2.85-.5-6h.5a10.06 10.06 0 003.69 5zm-2.3-28.62c.8-1.69 2.09-2.53 3.88-2.53 1.67 0 2.9 1 3.68 2.98.8 2 1.2 5 1.2 9.03 0 8.2-1.6 12.3-4.81 12.3-1.86 0-3.19-.98-4-2.92-.8-1.95-1.2-5.05-1.2-9.3v-1.22c.05-3.9.46-6.67 1.24-8.34zM161.64 55c-4.84 0-8.67-1.7-11.48-5.13-2.78-3.44-4.17-8.3-4.17-14.58 0-6.37 1.26-11.34 3.8-14.92 2.52-3.58 6.04-5.37 10.56-5.37 4.23 0 7.55 1.54 9.99 4.6 2.43 3.05 3.65 7.34 3.65 12.85v5.05h-18.5c.07 3.44.67 5.88 2.01 7.56a6.77 6.77 0 005.57 2.5c3.01 0 6.1-.94 9.25-2.81v7.58c-2.97 1.78-6.53 2.67-10.68 2.67zm-1.35-32.9c-1.33 0-2.42.7-3.27 2.11-.86 1.39-1.4 3.86-1.53 6.79h9.5c-.05-2.82-.55-5.26-1.37-6.72-.8-1.45-1.92-2.18-3.33-2.18zm36.2 8.9v23h9V29.2c0-4.64-.88-8.17-2.63-10.58C201.14 16.2 198.52 15 195 15c-2.08 0-3.9.51-5.44 1.53-1.55 1-2.74 2.68-3.57 4.47h-.5l-1.25-5H177v38h9.5V35.75c0-4.71.17-7.92 1.1-9.9.92-1.99 2.37-2.98 4.36-2.98 1.5 0 2.59.71 3.25 2.15A13.12 13.12 0 01196.5 31z"/></g><g class="b"><path d="M48.08 41a24.43 24.43 0 003.87-14.9c-.86-13.73-13.3-24.14-25.03-23.02-4.6.45-9.31 4.2-8.9 10.9.19 2.92 1.62 4.64 3.93 5.96C24.16 21.2 27 22 30.21 22.9c3.89 1.1 8.4 2.32 11.85 4.87 4.15 3.06 6.99 6.6 6.02 13.23z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M362.5 31v23h9V29c0-4.6-.9-8.09-2.7-10.45-1.8-2.38-4.52-3.55-8.05-3.55-3.83 0-6.9 2.24-8.75 6h-.5c.14-1.94.26-3.05.35-3.86.1-.84.15-1.36.15-2.14V.5h-9V54h9.5V35.5c0-4.15.14-7.22 1-9.42.85-2.22 2.34-3.33 4.46-3.33 2.84 0 4.54 2.63 4.54 8.25zM231.85 51.23c2.43-2.52 3.65-6.14 3.65-10.86 0-2.96-.67-5.59-2-7.9-1.3-2.3-3.63-4.56-6.98-6.77-2.48-1.62-4.22-3.06-5.23-4.33a7.08 7.08 0 01-1.47-4.46c0-1.73.41-3.1 1.23-4.08a4.39 4.39 0 013.58-1.53c1.4 0 2.7.26 3.93.76 1.23.51 2.41 1.09 3.54 1.73l3.15-7.54A21.76 21.76 0 00223.93 3c-4.12 0-7.4 1.27-9.86 3.8-2.43 2.54-3.65 5.98-3.65 10.32 0 2.26.3 4.24.91 5.95.63 1.7 1.51 3.25 2.63 4.63a24.91 24.91 0 005.02 4.3c2.53 1.7 4.34 3.26 5.44 4.66a7.22 7.22 0 011.65 4.6c0 1.71-.47 3.06-1.4 4.05-.92 1-2.29 1.49-4.11 1.49-3.2 0-6.72-1.23-10.56-3.7v9.3c3.13 1.74 6.93 2.6 11.4 2.6 4.56 0 8.04-1.26 10.45-3.77zm9.82-1.36c2.81 3.42 6.64 5.13 11.48 5.13 4.15 0 7.71-.89 10.68-2.67v-7.58c-3.15 1.87-6.24 2.8-9.25 2.8a6.77 6.77 0 01-5.57-2.49c-1.34-1.68-1.94-4.12-2.01-7.56h18.5v-5.05c0-5.51-1.22-9.8-3.65-12.84-2.44-3.07-5.76-4.61-9.99-4.61-4.52 0-8.04 1.79-10.57 5.37-2.53 3.58-3.79 8.55-3.79 14.92 0 6.28 1.4 11.14 4.17 14.58zm6.86-25.66c.85-1.4 1.94-2.11 3.27-2.11 1.41 0 2.52.73 3.33 2.18.82 1.46 1.32 3.9 1.37 6.72H247c.14-2.93.67-5.4 1.53-6.79zM288 54l-1.5-5h-.5c-1.38 2.26-2.7 3.87-4.18 4.72a10.99 10.99 0 01-5.57 1.28 8.17 8.17 0 01-6.8-3.18c-1.63-2.12-2.45-5.07-2.45-8.85 0-4.06 1.12-7.07 3.36-9.02 2.27-1.99 5.65-3.08 10.13-3.29l5.19-.2v-2.77c0-3.6-1.58-5.4-4.73-5.4-2.34 0-5.03.9-8.06 2.7l-3.23-6.36A23.23 23.23 0 01282.25 15c4.13 0 7.34 1.18 9.5 3.53 2.16 2.32 3.25 5.63 3.25 9.92V54h-7zm-7.93-6.2c1.7 0 3.06-.74 4.07-2.24 1.02-1.52 1.54-3.54 1.54-6.05v-3.25l-2.88.14c-2.12.12-3.69.71-4.7 1.8-.97 1.08-1.46 2.7-1.46 4.84 0 3.18 1.14 4.77 3.43 4.77zM318 15.76a14.31 14.31 0 00-3.78-.75 6.1 6.1 0 00-4.13 1.55A10.4 10.4 0 00307 21h-.5l-1.5-5h-7v38h9.46V34c0-3.36.22-5.52 1.4-7.27a5.76 5.76 0 015.09-2.66c1.02 0 1.91.2 2.55.43l1.5-8.75zM332 55c-4.56 0-8.05-1.52-10.43-4.87-2.38-3.35-3.57-8.27-3.57-14.75 0-6.8 1.12-11.86 3.37-15.2 2.26-3.35 5.65-5.18 10.37-5.18 1.41 0 3.01.36 4.57.78 1.56.41 3.45.94 4.69 1.72l-3.11 7.24c-1.9-1.13-3.58-1.7-5.05-1.7-1.95 0-3.35 1.04-4.23 3.09-.84 2.03-1.27 5.1-1.27 9.18 0 4 .43 6.98 1.27 8.97.85 1.96 2.24 2.94 4.16 2.94 2.3 0 4.68-.8 7.18-2.42v8.1c-2.4 1.5-5.04 2.1-7.95 2.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -0,0 +1,47 @@
[![Go Reference](https://pkg.go.dev/badge/github.com/opensearch-project/opensearch-go.svg)](https://pkg.go.dev/github.com/opensearch-project/opensearch-go)
[![Build](https://github.com/opensearch-project/opensearch-go/actions/workflows/build.yml/badge.svg)](https://github.com/opensearch-project/opensearch-go/actions/workflows/build.yml)
[![Unit](https://github.com/opensearch-project/opensearch-go/actions/workflows/test-unit.yml/badge.svg)](https://github.com/opensearch-project/opensearch-go/actions/workflows/test-unit.yml)
[![Integration](https://github.com/opensearch-project/opensearch-go/actions/workflows/test-integration.yml/badge.svg)](https://github.com/opensearch-project/opensearch-go/actions/workflows/test-integration.yml)
[![codecov](https://codecov.io/gh/opensearch-project/opensearch-go/branch/main/graph/badge.svg?token=MI9g3KYHVx)](https://codecov.io/gh/opensearch-project/opensearch-go)
[![Chat](https://img.shields.io/badge/chat-on%20forums-blue)](https://discuss.opendistrocommunity.dev/c/clients/)
![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success)
![OpenSearch logo](OpenSearch.svg)
OpenSearch Go Client
- [Welcome!](#welcome)
- [Project Resources](#project-resources)
- [Code of Conduct](#code-of-conduct)
- [License](#license)
- [Copyright](#copyright)
## Welcome!
**opensearch-go** is [a community-driven, open source fork](https://aws.amazon.com/blogs/opensource/introducing-opensearch/) of go-elasticsearch licensed under the [Apache v2.0 License](LICENSE.txt). For more information, see [opensearch.org](https://opensearch.org/).
## Project Resources
* [Project Website](https://opensearch.org/)
* [Developer Guide](DEVELOPER_GUIDE.md)
* [User Guide](USER_GUIDE.md)
* [Documentation](https://opensearch.org/docs/)
* Need help? Try [Forums](https://discuss.opendistrocommunity.dev/c/clients/)
* [Project Principles](https://opensearch.org/#principles)
* [Contributing to OpenSearch](CONTRIBUTING.md)
* [Maintainer Responsibilities](MAINTAINERS.md)
* [Release Management](RELEASING.md)
* [Admin Responsibilities](ADMINS.md)
* [Security](SECURITY.md)
## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](CODE_OF_CONDUCT.md). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq), or contact [opensource-codeofconduct@amazon.com](mailto:opensource-codeofconduct@amazon.com) with any additional questions or comments.
## License
This project is licensed under the [Apache v2.0 License](LICENSE.txt).
## Copyright
Copyright OpenSearch Contributors. See [NOTICE](NOTICE.txt) for details.

View File

@@ -0,0 +1,34 @@
- [Overview](#overview)
- [Branching](#branching)
- [Release Branching](#release-branching)
- [Feature Branches](#feature-branches)
- [Release Labels](#release-labels)
- [Releasing](#releasing)
## Overview
This document explains the release strategy for artifacts in this organization.
## Branching
### Release Branching
Given the current major release of 1.0, projects in this organization maintain the following active branches.
* **main**: The next _major_ release. This is the branch where all merges take place and code moves fast.
* **1.x**: The next _minor_ release. Once a change is merged into `main`, decide whether to backport it to `1.x`.
* **1.0**: The _current_ release. In between minor releases, only hotfixes (e.g. security) are backported to `1.0`.
Label PRs with the next major version label (e.g. `2.0.0`) and merge changes into `main`. Label PRs that you believe need to be backported as `1.x` and `1.0`. Backport PRs by checking out the versioned branch, cherry-pick changes and open a PR against each target backport branch.
### Feature Branches
Do not creating branches in the upstream repo, use your fork, for the exception of long lasting feature branches that require active collaboration from multiple developers. Name feature branches `feature/<thing>`. Once the work is merged to `main`, please make sure to delete the feature branch.
## Release Labels
Repositories create consistent release labels, such as `v1.0.0`, `v1.1.0` and `v2.0.0`, as well as `patch` and `backport`. Use release labels to target an issue or a PR for a given release. See [MAINTAINERS](MAINTAINERS.md#triage-open-issues) for more information on triaging issues.
## Releasing
The release process is standard across repositories in this org and is run by a release manager volunteering from amongst [MAINTAINERS](MAINTAINERS.md).

View File

@@ -0,0 +1,3 @@
## Reporting a Vulnerability
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue.

View File

@@ -0,0 +1,127 @@
# User Guide
## Example
In the example below, we create a client, an index with non-default settings, insert a document to the index,
search for the document, delete the document and finally delete the index.
```go
package main
import (
"os"
"context"
"crypto/tls"
"fmt"
opensearch "github.com/opensearch-project/opensearch-go"
opensearchapi "github.com/opensearch-project/opensearch-go/opensearchapi"
"net/http"
"strings"
)
const IndexName = "go-test-index1"
func main() {
// Initialize the client with SSL/TLS enabled.
client, err := opensearch.NewClient(opensearch.Config{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // For testing only. Use certificate for validation.
},
Addresses: []string{"https://localhost:9200"},
Username: "admin", // For testing only. Don't store credentials in code.
Password: "admin",
})
if err != nil {
fmt.Println("cannot initialize", err)
os.Exit(1)
}
// Print OpenSearch version information on console.
fmt.Println(client.Info())
// Define index mapping.
mapping := strings.NewReader(`{
'settings': {
'index': {
'number_of_shards': 4
}
}
}`)
// Create an index with non-default settings.
res := opensearchapi.CreateRequest{
Index: IndexName,
Body: mapping,
}
fmt.Println("creating index", res)
// Add a document to the index.
document := strings.NewReader(`{
"title": "Moneyball",
"director": "Bennett Miller",
"year": "2011"
}`)
docId := "1"
req := opensearchapi.IndexRequest{
Index: IndexName,
DocumentID: docId,
Body: document,
}
insertResponse, err := req.Do(context.Background(), client)
if err != nil {
fmt.Println("failed to insert document ", err)
os.Exit(1)
}
fmt.Println(insertResponse)
// Search for the document.
content := strings.NewReader(`{
"size": 5,
"query": {
"multi_match": {
"query": "miller",
"fields": ["title^2", "director"]
}
}
}`)
search := opensearchapi.SearchRequest{
Body: content,
}
searchResponse, err := search.Do(context.Background(), client)
if err != nil {
fmt.Println("failed to search document ", err)
os.Exit(1)
}
fmt.Println(searchResponse)
// Delete the document.
delete := opensearchapi.DeleteRequest{
Index: IndexName,
DocumentID: docId,
}
deleteResponse, err := delete.Do(context.Background(), client)
if err != nil {
fmt.Println("failed to delete document ", err)
os.Exit(1)
}
fmt.Println("deleting document")
fmt.Println(deleteResponse)
// Delete previously created index.
deleteIndex := opensearchapi.IndicesDeleteRequest{
Index: []string{IndexName},
}
deleteIndexResponse, err := deleteIndex.Do(context.Background(), client)
if err != nil {
fmt.Println("failed to delete index ", err)
os.Exit(1)
}
fmt.Println("deleting index", deleteIndexResponse)
}
```

View File

@@ -0,0 +1,74 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to opensearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
/*
Package opensearch provides a Go client for OpenSearch.
Create the client with the NewDefaultClient function:
opensearch.NewDefaultClient()
The OPENSEARCH_URL/ELASTICSEARCH_URL environment variable is used instead of the default URL, when set.
Use a comma to separate multiple URLs.
It is an error to set both environment variable.
To configure the client, pass a Config object to the NewClient function:
cfg := opensearch.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,
},
},
}
opensearch.NewClient(cfg)
See the opensearch_integration_test.go file for more information.
Call the OpenSearch APIs by invoking the corresponding methods on the client:
res, err := client.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
log.Println(res)
See the github.com/opensearch-project/opensearch-go/opensearchapi package for more information about using the API.
See the github.com/opensearch-project/opensearch-go/opensearchtransport package for more information about configuring the transport.
*/
package opensearch

View File

@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package version
// Client returns the client version as a string.
//
const Client = "1.0.0"

View File

@@ -0,0 +1,402 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearch
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/opensearch-project/opensearch-go/signer"
"github.com/opensearch-project/opensearch-go/internal/version"
"github.com/opensearch-project/opensearch-go/opensearchapi"
"github.com/opensearch-project/opensearch-go/opensearchtransport"
)
var (
reVersion *regexp.Regexp
)
func init() {
versionPattern := `^([0-9]+)\.([0-9]+)\.([0-9]+)`
reVersion = regexp.MustCompile(versionPattern)
}
const (
defaultURL = "http://localhost:9200"
openSearch = "opensearch"
unsupportedProduct = "the client noticed that the server is not a supported distribution"
envOpenSearchURL = "OPENSEARCH_URL"
envElasticsearchURL = "ELASTICSEARCH_URL"
)
// 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 nodes to use.
Username string // Username for HTTP Basic Authentication.
Password string // Password for HTTP Basic Authentication.
Header http.Header // Global HTTP request header.
Signer signer.Signer
// PEM-encoded certificate authorities.
// When set, an empty certificate pool will be created, and the certificates will be appended to it.
// The option is only valid when the transport is not specified, or when it's http.Transport.
CACert []byte
RetryOnStatus []int // List of status codes for retry. Default: 502, 503, 504.
DisableRetry bool // Default: false.
EnableRetryOnTimeout bool // Default: false.
MaxRetries int // Default: 3.
CompressRequestBody bool // Default: false.
DiscoverNodesOnStart bool // Discover nodes when initializing the client. Default: false.
DiscoverNodesInterval time.Duration // Discover nodes periodically. Default: disabled.
EnableMetrics bool // Enable the metrics collection.
EnableDebugLogger bool // Enable the debug logging.
UseResponseCheckOnly bool
RetryBackoff func(attempt int) time.Duration // Optional backoff duration. Default: nil.
Transport http.RoundTripper // The HTTP transport object.
Logger opensearchtransport.Logger // The logger object.
Selector opensearchtransport.Selector // The selector object.
// Optional constructor function for a custom ConnectionPool. Default: nil.
ConnectionPoolFunc func([]*opensearchtransport.Connection, opensearchtransport.Selector) opensearchtransport.ConnectionPool
}
// Client represents the OpenSearch client.
//
type Client struct {
*opensearchapi.API // Embeds the API methods
Transport opensearchtransport.Interface
useResponseCheckOnly bool
productCheckMu sync.RWMutex
productCheckSuccess bool
}
type esVersion struct {
Number string `json:"number"`
BuildFlavor string `json:"build_flavor"`
Distribution string `json:"distribution"`
}
type info struct {
Version esVersion `json:"version"`
Tagline string `json:"tagline"`
}
// NewDefaultClient creates a new client with default options.
//
// It will use http://localhost:9200 as the default address.
//
// It will use the OPENSEARCH_URL/ELASTICSEARCH_URL environment variable, if set,
// to configure the addresses; use a comma to separate multiple URLs.
//
// It's an error to set both OPENSEARCH_URL and ELASTICSEARCH_URL.
//
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 OPENSEARCH_URL/ELASTICSEARCH_URL environment variable, if set,
// to configure the addresses; use a comma to separate multiple URLs.
//
// It's an error to set both OPENSEARCH_URL and ELASTICSEARCH_URL.
//
func NewClient(cfg Config) (*Client, error) {
var addrs []string
if len(cfg.Addresses) == 0 {
envAddress, err := getAddressFromEnvironment()
if err != nil {
return nil, err
}
addrs = envAddress
} else {
addrs = append(addrs, 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)
}
// TODO: Refactor
if urls[0].User != nil {
cfg.Username = urls[0].User.Username()
pw, _ := urls[0].User.Password()
cfg.Password = pw
}
tp, err := opensearchtransport.New(opensearchtransport.Config{
URLs: urls,
Username: cfg.Username,
Password: cfg.Password,
Header: cfg.Header,
CACert: cfg.CACert,
Signer: cfg.Signer,
RetryOnStatus: cfg.RetryOnStatus,
DisableRetry: cfg.DisableRetry,
EnableRetryOnTimeout: cfg.EnableRetryOnTimeout,
MaxRetries: cfg.MaxRetries,
RetryBackoff: cfg.RetryBackoff,
CompressRequestBody: cfg.CompressRequestBody,
EnableMetrics: cfg.EnableMetrics,
EnableDebugLogger: cfg.EnableDebugLogger,
DiscoverNodesInterval: cfg.DiscoverNodesInterval,
Transport: cfg.Transport,
Logger: cfg.Logger,
Selector: cfg.Selector,
ConnectionPoolFunc: cfg.ConnectionPoolFunc,
})
if err != nil {
return nil, fmt.Errorf("error creating transport: %s", err)
}
client := &Client{Transport: tp, useResponseCheckOnly: cfg.UseResponseCheckOnly}
client.API = opensearchapi.New(client)
if cfg.DiscoverNodesOnStart {
go client.DiscoverNodes()
}
return client, err
}
func getAddressFromEnvironment() ([]string, error) {
fromOpenSearchEnv := addrsFromEnvironment(envOpenSearchURL)
fromElasticsearchEnv := addrsFromEnvironment(envElasticsearchURL)
if len(fromElasticsearchEnv) > 0 && len(fromOpenSearchEnv) > 0 {
return nil, fmt.Errorf("cannot create client: both %s and %s are set", envOpenSearchURL, envElasticsearchURL)
}
if len(fromOpenSearchEnv) > 0 {
return fromOpenSearchEnv, nil
}
return fromElasticsearchEnv, nil
}
// checkCompatibleInfo validates the information given by OpenSearch
//
func checkCompatibleInfo(info info) error {
major, _, _, err := ParseVersion(info.Version.Number)
if err != nil {
return err
}
if info.Version.Distribution == openSearch {
return nil
}
if major != 7 {
return errors.New(unsupportedProduct)
}
return nil
}
// ParseVersion returns an int64 representation of version.
//
func ParseVersion(version string) (int64, int64, int64, error) {
matches := reVersion.FindStringSubmatch(version)
if len(matches) < 4 {
return 0, 0, 0, fmt.Errorf("")
}
major, _ := strconv.ParseInt(matches[1], 10, 0)
minor, _ := strconv.ParseInt(matches[2], 10, 0)
patch, _ := strconv.ParseInt(matches[3], 10, 0)
return major, minor, patch, nil
}
// Perform delegates to Transport to execute a request and return a response.
//
func (c *Client) Perform(req *http.Request) (*http.Response, error) {
if !c.useResponseCheckOnly {
// Launch product check, request info, check header then payload.
if err := c.doProductCheck(c.productCheck); err != nil {
return nil, err
}
}
// Retrieve the original request.
return c.Transport.Perform(req)
}
// doProductCheck calls f if there as not been a prior successful call to doProductCheck,
// returning nil otherwise.
func (c *Client) doProductCheck(f func() error) error {
c.productCheckMu.RLock()
productCheckSuccess := c.productCheckSuccess
c.productCheckMu.RUnlock()
if productCheckSuccess {
return nil
}
c.productCheckMu.Lock()
defer c.productCheckMu.Unlock()
if c.productCheckSuccess {
return nil
}
if err := f(); err != nil {
return err
}
c.productCheckSuccess = true
return nil
}
// productCheck runs an opensearchapi.Info query to retrieve information of the current cluster
// decodes the response and decides if the cluster can be supported or not.
func (c *Client) productCheck() error {
req := opensearchapi.InfoRequest{}
res, err := req.Do(context.Background(), c.Transport)
if err != nil {
return err
}
defer res.Body.Close()
if res.IsError() {
_, err = io.Copy(ioutil.Discard, res.Body)
if err != nil {
return err
}
switch res.StatusCode {
case http.StatusUnauthorized:
return nil
case http.StatusForbidden:
return nil
default:
return fmt.Errorf("cannot retrieve information from OpenSearch")
}
}
var info info
contentType := res.Header.Get("Content-Type")
if strings.Contains(contentType, "json") {
err = json.NewDecoder(res.Body).Decode(&info)
if err != nil {
return fmt.Errorf("error decoding OpenSearch informations: %s", err)
}
}
if info.Version.Number != "" {
return checkCompatibleInfo(info)
}
return nil
}
// Metrics returns the client metrics.
//
func (c *Client) Metrics() (opensearchtransport.Metrics, error) {
if mt, ok := c.Transport.(opensearchtransport.Measurable); ok {
return mt.Metrics()
}
return opensearchtransport.Metrics{}, errors.New("transport is missing method Metrics()")
}
// DiscoverNodes reloads the client connections by fetching information from the cluster.
//
func (c *Client) DiscoverNodes() error {
if dt, ok := c.Transport.(opensearchtransport.Discoverable); ok {
return dt.DiscoverNodes()
}
return errors.New("transport is missing method DiscoverNodes()")
}
// addrsFromEnvironment returns a list of addresses by splitting
// the given environment variable with comma, or an empty list.
//
func addrsFromEnvironment(name string) []string {
var addrs []string
if envURLs, ok := os.LookupEnv(name); 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,393 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
// API contains the OpenSearch APIs
//
type API struct {
Cat *Cat
Cluster *Cluster
Indices *Indices
Ingest *Ingest
Nodes *Nodes
Remote *Remote
Snapshot *Snapshot
Tasks *Tasks
Bulk Bulk
ClearScroll ClearScroll
Count Count
Create Create
DanglingIndicesDeleteDanglingIndex DanglingIndicesDeleteDanglingIndex
DanglingIndicesImportDanglingIndex DanglingIndicesImportDanglingIndex
DanglingIndicesListDanglingIndices DanglingIndicesListDanglingIndices
DeleteByQuery DeleteByQuery
DeleteByQueryRethrottle DeleteByQueryRethrottle
Delete Delete
DeleteScript DeleteScript
Exists Exists
ExistsSource ExistsSource
Explain Explain
FieldCaps FieldCaps
Get Get
GetScriptContext GetScriptContext
GetScriptLanguages GetScriptLanguages
GetScript GetScript
GetSource GetSource
Index Index
Info Info
Mget Mget
Msearch Msearch
MsearchTemplate MsearchTemplate
Mtermvectors Mtermvectors
Ping Ping
PutScript PutScript
RankEval RankEval
Reindex Reindex
ReindexRethrottle ReindexRethrottle
RenderSearchTemplate RenderSearchTemplate
ScriptsPainlessExecute ScriptsPainlessExecute
Scroll Scroll
Search Search
SearchShards SearchShards
SearchTemplate SearchTemplate
TermsEnum TermsEnum
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
DeleteComponentTemplate ClusterDeleteComponentTemplate
DeleteVotingConfigExclusions ClusterDeleteVotingConfigExclusions
ExistsComponentTemplate ClusterExistsComponentTemplate
GetComponentTemplate ClusterGetComponentTemplate
GetSettings ClusterGetSettings
Health ClusterHealth
PendingTasks ClusterPendingTasks
PostVotingConfigExclusions ClusterPostVotingConfigExclusions
PutComponentTemplate ClusterPutComponentTemplate
PutSettings ClusterPutSettings
RemoteInfo ClusterRemoteInfo
Reroute ClusterReroute
State ClusterState
Stats ClusterStats
}
// Indices contains the Indices APIs
type Indices struct {
AddBlock IndicesAddBlock
Analyze IndicesAnalyze
ClearCache IndicesClearCache
Clone IndicesClone
Close IndicesClose
Create IndicesCreate
DeleteAlias IndicesDeleteAlias
DeleteIndexTemplate IndicesDeleteIndexTemplate
Delete IndicesDelete
DeleteTemplate IndicesDeleteTemplate
DiskUsage IndicesDiskUsage
ExistsAlias IndicesExistsAlias
ExistsDocumentType IndicesExistsDocumentType
ExistsIndexTemplate IndicesExistsIndexTemplate
Exists IndicesExists
ExistsTemplate IndicesExistsTemplate
FieldUsageStats IndicesFieldUsageStats
Flush IndicesFlush
FlushSynced IndicesFlushSynced
Forcemerge IndicesForcemerge
GetAlias IndicesGetAlias
GetFieldMapping IndicesGetFieldMapping
GetIndexTemplate IndicesGetIndexTemplate
GetMapping IndicesGetMapping
Get IndicesGet
GetSettings IndicesGetSettings
GetTemplate IndicesGetTemplate
GetUpgrade IndicesGetUpgrade
Open IndicesOpen
PutAlias IndicesPutAlias
PutIndexTemplate IndicesPutIndexTemplate
PutMapping IndicesPutMapping
PutSettings IndicesPutSettings
PutTemplate IndicesPutTemplate
Recovery IndicesRecovery
Refresh IndicesRefresh
ResolveIndex IndicesResolveIndex
Rollover IndicesRollover
Segments IndicesSegments
ShardStores IndicesShardStores
Shrink IndicesShrink
SimulateIndexTemplate IndicesSimulateIndexTemplate
SimulateTemplate IndicesSimulateTemplate
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 {
CleanupRepository SnapshotCleanupRepository
Clone SnapshotClone
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),
Count: newCountFunc(t),
Create: newCreateFunc(t),
DanglingIndicesDeleteDanglingIndex: newDanglingIndicesDeleteDanglingIndexFunc(t),
DanglingIndicesImportDanglingIndex: newDanglingIndicesImportDanglingIndexFunc(t),
DanglingIndicesListDanglingIndices: newDanglingIndicesListDanglingIndicesFunc(t),
DeleteByQuery: newDeleteByQueryFunc(t),
DeleteByQueryRethrottle: newDeleteByQueryRethrottleFunc(t),
Delete: newDeleteFunc(t),
DeleteScript: newDeleteScriptFunc(t),
Exists: newExistsFunc(t),
ExistsSource: newExistsSourceFunc(t),
Explain: newExplainFunc(t),
FieldCaps: newFieldCapsFunc(t),
Get: newGetFunc(t),
GetScriptContext: newGetScriptContextFunc(t),
GetScriptLanguages: newGetScriptLanguagesFunc(t),
GetScript: newGetScriptFunc(t),
GetSource: newGetSourceFunc(t),
Index: newIndexFunc(t),
Info: newInfoFunc(t),
Mget: newMgetFunc(t),
Msearch: newMsearchFunc(t),
MsearchTemplate: newMsearchTemplateFunc(t),
Mtermvectors: newMtermvectorsFunc(t),
Ping: newPingFunc(t),
PutScript: newPutScriptFunc(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),
TermsEnum: newTermsEnumFunc(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),
DeleteComponentTemplate: newClusterDeleteComponentTemplateFunc(t),
DeleteVotingConfigExclusions: newClusterDeleteVotingConfigExclusionsFunc(t),
ExistsComponentTemplate: newClusterExistsComponentTemplateFunc(t),
GetComponentTemplate: newClusterGetComponentTemplateFunc(t),
GetSettings: newClusterGetSettingsFunc(t),
Health: newClusterHealthFunc(t),
PendingTasks: newClusterPendingTasksFunc(t),
PostVotingConfigExclusions: newClusterPostVotingConfigExclusionsFunc(t),
PutComponentTemplate: newClusterPutComponentTemplateFunc(t),
PutSettings: newClusterPutSettingsFunc(t),
RemoteInfo: newClusterRemoteInfoFunc(t),
Reroute: newClusterRerouteFunc(t),
State: newClusterStateFunc(t),
Stats: newClusterStatsFunc(t),
},
Indices: &Indices{
AddBlock: newIndicesAddBlockFunc(t),
Analyze: newIndicesAnalyzeFunc(t),
ClearCache: newIndicesClearCacheFunc(t),
Clone: newIndicesCloneFunc(t),
Close: newIndicesCloseFunc(t),
Create: newIndicesCreateFunc(t),
DeleteAlias: newIndicesDeleteAliasFunc(t),
DeleteIndexTemplate: newIndicesDeleteIndexTemplateFunc(t),
Delete: newIndicesDeleteFunc(t),
DeleteTemplate: newIndicesDeleteTemplateFunc(t),
DiskUsage: newIndicesDiskUsageFunc(t),
ExistsAlias: newIndicesExistsAliasFunc(t),
ExistsDocumentType: newIndicesExistsDocumentTypeFunc(t),
ExistsIndexTemplate: newIndicesExistsIndexTemplateFunc(t),
Exists: newIndicesExistsFunc(t),
ExistsTemplate: newIndicesExistsTemplateFunc(t),
FieldUsageStats: newIndicesFieldUsageStatsFunc(t),
Flush: newIndicesFlushFunc(t),
FlushSynced: newIndicesFlushSyncedFunc(t),
Forcemerge: newIndicesForcemergeFunc(t),
GetAlias: newIndicesGetAliasFunc(t),
GetFieldMapping: newIndicesGetFieldMappingFunc(t),
GetIndexTemplate: newIndicesGetIndexTemplateFunc(t),
GetMapping: newIndicesGetMappingFunc(t),
Get: newIndicesGetFunc(t),
GetSettings: newIndicesGetSettingsFunc(t),
GetTemplate: newIndicesGetTemplateFunc(t),
GetUpgrade: newIndicesGetUpgradeFunc(t),
Open: newIndicesOpenFunc(t),
PutAlias: newIndicesPutAliasFunc(t),
PutIndexTemplate: newIndicesPutIndexTemplateFunc(t),
PutMapping: newIndicesPutMappingFunc(t),
PutSettings: newIndicesPutSettingsFunc(t),
PutTemplate: newIndicesPutTemplateFunc(t),
Recovery: newIndicesRecoveryFunc(t),
Refresh: newIndicesRefreshFunc(t),
ResolveIndex: newIndicesResolveIndexFunc(t),
Rollover: newIndicesRolloverFunc(t),
Segments: newIndicesSegmentsFunc(t),
ShardStores: newIndicesShardStoresFunc(t),
Shrink: newIndicesShrinkFunc(t),
SimulateIndexTemplate: newIndicesSimulateIndexTemplateFunc(t),
SimulateTemplate: newIndicesSimulateTemplateFunc(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{
CleanupRepository: newSnapshotCleanupRepositoryFunc(t),
Clone: newSnapshotCloneFunc(t),
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,361 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"io"
"net/http"
"strconv"
"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.
//
//
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
Pipeline string
Refresh string
RequireAlias *bool
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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 r.Pipeline != "" {
params["pipeline"] = r.Pipeline
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.RequireAlias != nil {
params["require_alias"] = strconv.FormatBool(*r.RequireAlias)
}
if r.Routing != "" {
params["routing"] = r.Routing
}
if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
}
if len(r.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// 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 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 Bulk) WithRefresh(v string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Refresh = v
}
}
// WithRequireAlias - sets require_alias for all incoming documents. defaults to unset (false).
//
func (f Bulk) WithRequireAlias(v bool) func(*BulkRequest) {
return func(r *BulkRequest) {
r.RequireAlias = &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
}
}
// WithSourceExcludes - default list of fields to exclude from the returned _source field, can be overridden on each sub-request.
//
func (f Bulk) WithSourceExcludes(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - default list of fields to extract and return from the _source field, can be overridden on each sub-request.
//
func (f Bulk) WithSourceIncludes(v ...string) func(*BulkRequest) {
return func(r *BulkRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Bulk) WithOpaqueID(s string) func(*BulkRequest) {
return func(r *BulkRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,312 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
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.
//
//
type CatAliases func(o ...func(*CatAliasesRequest)) (*Response, error)
// CatAliasesRequest configures the Cat Aliases API request.
//
type CatAliasesRequest struct {
Name []string
ExpandWildcards string
Format string
H []string
Help *bool
Local *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 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.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
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 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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f CatAliases) WithExpandWildcards(v string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
r.ExpandWildcards = 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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatAliases) WithOpaqueID(s string) func(*CatAliasesRequest) {
return func(r *CatAliasesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,327 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
//
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatAllocation) WithOpaqueID(s string) func(*CatAllocationRequest) {
return func(r *CatAllocationRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,287 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
//
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
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.
//
//
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
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 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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatCount) WithOpaqueID(s string) func(*CatCountRequest) {
return func(r *CatCountRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,304 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
//
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
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.
//
//
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
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 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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatFielddata) WithOpaqueID(s string) func(*CatFielddataRequest) {
return func(r *CatFielddataRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,296 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
//
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
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.
//
//
type CatHealth func(o ...func(*CatHealthRequest)) (*Response, error)
// CatHealthRequest configures the Cat Health API request.
//
type CatHealthRequest struct {
Format string
H []string
Help *bool
S []string
Time 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 len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatHealth) WithTime(v string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatHealth) WithOpaqueID(s string) func(*CatHealthRequest) {
return func(r *CatHealthRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,230 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatHelp) WithOpaqueID(s string) func(*CatHelpRequest) {
return func(r *CatHelpRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,391 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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, ...
//
//
type CatIndices func(o ...func(*CatIndicesRequest)) (*Response, error)
// CatIndicesRequest configures the Cat Indices API request.
//
type CatIndicesRequest struct {
Index []string
Bytes string
ExpandWildcards string
Format string
H []string
Health string
Help *bool
IncludeUnloadedSegments *bool
Local *bool
MasterTimeout time.Duration
Pri *bool
S []string
Time 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.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
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.IncludeUnloadedSegments != nil {
params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments)
}
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.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f CatIndices) WithExpandWildcards(v string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.ExpandWildcards = 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
}
}
// WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory.
//
func (f CatIndices) WithIncludeUnloadedSegments(v bool) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.IncludeUnloadedSegments = &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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatIndices) WithTime(v string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatIndices) WithOpaqueID(s string) func(*CatIndicesRequest) {
return func(r *CatIndicesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,296 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatMaster) WithOpaqueID(s string) func(*CatMasterRequest) {
return func(r *CatMasterRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,296 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatNodeattrs) WithOpaqueID(s string) func(*CatNodeattrsRequest) {
return func(r *CatNodeattrsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,348 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
type CatNodes func(o ...func(*CatNodesRequest)) (*Response, error)
// CatNodesRequest configures the Cat Nodes API request.
//
type CatNodesRequest struct {
Bytes string
Format string
FullID *bool
H []string
Help *bool
IncludeUnloadedSegments *bool
Local *bool
MasterTimeout time.Duration
S []string
Time 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.Bytes != "" {
params["bytes"] = r.Bytes
}
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.IncludeUnloadedSegments != nil {
params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments)
}
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.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithBytes - the unit in which to display byte values.
//
func (f CatNodes) WithBytes(v string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Bytes = 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
}
}
// WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory.
//
func (f CatNodes) WithIncludeUnloadedSegments(v bool) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.IncludeUnloadedSegments = &v
}
}
// WithLocal - calculate the selected nodes using the local cluster state rather than 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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatNodes) WithTime(v string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatNodes) WithOpaqueID(s string) func(*CatNodesRequest) {
return func(r *CatNodesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,309 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Time 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.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatPendingTasks) WithTime(v string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatPendingTasks) WithOpaqueID(s string) func(*CatPendingTasksRequest) {
return func(r *CatPendingTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,309 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
type CatPlugins func(o ...func(*CatPluginsRequest)) (*Response, error)
// CatPluginsRequest configures the Cat Plugins API request.
//
type CatPluginsRequest struct {
Format string
H []string
Help *bool
IncludeBootstrap *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.IncludeBootstrap != nil {
params["include_bootstrap"] = strconv.FormatBool(*r.IncludeBootstrap)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithIncludeBootstrap - include bootstrap plugins in the response.
//
func (f CatPlugins) WithIncludeBootstrap(v bool) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
r.IncludeBootstrap = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatPlugins) WithOpaqueID(s string) func(*CatPluginsRequest) {
return func(r *CatPluginsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,342 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
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.
//
//
type CatRecovery func(o ...func(*CatRecoveryRequest)) (*Response, error)
// CatRecoveryRequest configures the Cat Recovery API request.
//
type CatRecoveryRequest struct {
Index []string
ActiveOnly *bool
Bytes string
Detailed *bool
Format string
H []string
Help *bool
S []string
Time 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.ActiveOnly != nil {
params["active_only"] = strconv.FormatBool(*r.ActiveOnly)
}
if r.Bytes != "" {
params["bytes"] = r.Bytes
}
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.Index) > 0 {
params["index"] = strings.Join(r.Index, ",")
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 - comma-separated list or wildcard expression of index names to limit the returned information.
//
func (f CatRecovery) WithIndex(v ...string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Index = v
}
}
// WithActiveOnly - if `true`, the response only includes ongoing shard recoveries.
//
func (f CatRecovery) WithActiveOnly(v bool) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.ActiveOnly = &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
}
}
// WithDetailed - if `true`, the response includes detailed information about shard recoveries.
//
func (f CatRecovery) WithDetailed(v bool) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Detailed = &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
}
}
// 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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatRecovery) WithTime(v string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatRecovery) WithOpaqueID(s string) func(*CatRecoveryRequest) {
return func(r *CatRecoveryRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,296 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatRepositories) WithOpaqueID(s string) func(*CatRepositoriesRequest) {
return func(r *CatRepositoriesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,299 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatSegments) WithOpaqueID(s string) func(*CatSegmentsRequest) {
return func(r *CatSegmentsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,339 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Time 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.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatShards) WithTime(v string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatShards) WithOpaqueID(s string) func(*CatShardsRequest) {
return func(r *CatShardsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,326 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newCatSnapshotsFunc(t Transport) CatSnapshots {
return func(o ...func(*CatSnapshotsRequest)) (*Response, error) {
var r = CatSnapshotsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// CatSnapshots returns all snapshots in a specific repository.
//
//
type CatSnapshots func(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
Time 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")
if len(r.Repository) > 0 {
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.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithRepository - name of repository from which to fetch the snapshot information.
//
func (f CatSnapshots) WithRepository(v ...string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Repository = 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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatSnapshots) WithTime(v string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatSnapshots) WithOpaqueID(s string) func(*CatSnapshotsRequest) {
return func(r *CatSnapshotsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,334 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Nodes []string
ParentTaskID string
S []string
Time 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.Nodes) > 0 {
params["nodes"] = strings.Join(r.Nodes, ",")
}
if r.ParentTaskID != "" {
params["parent_task_id"] = r.ParentTaskID
}
if len(r.S) > 0 {
params["s"] = strings.Join(r.S, ",")
}
if r.Time != "" {
params["time"] = r.Time
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithNodes - 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) WithNodes(v ...string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Nodes = v
}
}
// WithParentTaskID - return tasks with specified parent task ID (node_id:task_number). set to -1 to return all..
//
func (f CatTasks) WithParentTaskID(v string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.ParentTaskID = 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
}
}
// WithTime - the unit in which to display time values.
//
func (f CatTasks) WithTime(v string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
r.Time = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatTasks) WithOpaqueID(s string) func(*CatTasksRequest) {
return func(r *CatTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,313 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatTemplates) WithOpaqueID(s string) func(*CatTemplatesRequest) {
return func(r *CatTemplatesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,327 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f CatThreadPool) WithOpaqueID(s string) func(*CatThreadPoolRequest) {
return func(r *CatThreadPoolRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,234 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClearScroll) WithOpaqueID(s string) func(*ClearScrollRequest) {
return func(r *ClearScrollRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,245 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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 = "POST"
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterAllocationExplain) WithOpaqueID(s string) func(*ClusterAllocationExplainRequest) {
return func(r *ClusterAllocationExplainRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,235 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
"time"
)
func newClusterDeleteComponentTemplateFunc(t Transport) ClusterDeleteComponentTemplate {
return func(name string, o ...func(*ClusterDeleteComponentTemplateRequest)) (*Response, error) {
var r = ClusterDeleteComponentTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterDeleteComponentTemplate deletes a component template
//
//
type ClusterDeleteComponentTemplate func(name string, o ...func(*ClusterDeleteComponentTemplateRequest)) (*Response, error)
// ClusterDeleteComponentTemplateRequest configures the Cluster Delete Component Template API request.
//
type ClusterDeleteComponentTemplateRequest 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 ClusterDeleteComponentTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_component_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_component_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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 ClusterDeleteComponentTemplate) WithContext(v context.Context) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f ClusterDeleteComponentTemplate) WithMasterTimeout(v time.Duration) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterDeleteComponentTemplate) WithTimeout(v time.Duration) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterDeleteComponentTemplate) WithPretty() func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterDeleteComponentTemplate) WithHuman() func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterDeleteComponentTemplate) WithErrorTrace() func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterDeleteComponentTemplate) WithFilterPath(v ...string) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterDeleteComponentTemplate) WithHeader(h map[string]string) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterDeleteComponentTemplate) WithOpaqueID(s string) func(*ClusterDeleteComponentTemplateRequest) {
return func(r *ClusterDeleteComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,217 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newClusterDeleteVotingConfigExclusionsFunc(t Transport) ClusterDeleteVotingConfigExclusions {
return func(o ...func(*ClusterDeleteVotingConfigExclusionsRequest)) (*Response, error) {
var r = ClusterDeleteVotingConfigExclusionsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterDeleteVotingConfigExclusions clears cluster voting config exclusions.
//
//
type ClusterDeleteVotingConfigExclusions func(o ...func(*ClusterDeleteVotingConfigExclusionsRequest)) (*Response, error)
// ClusterDeleteVotingConfigExclusionsRequest configures the Cluster Delete Voting Config Exclusions API request.
//
type ClusterDeleteVotingConfigExclusionsRequest struct {
WaitForRemoval *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 ClusterDeleteVotingConfigExclusionsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(len("/_cluster/voting_config_exclusions"))
path.WriteString("/_cluster/voting_config_exclusions")
params = make(map[string]string)
if r.WaitForRemoval != nil {
params["wait_for_removal"] = strconv.FormatBool(*r.WaitForRemoval)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 ClusterDeleteVotingConfigExclusions) WithContext(v context.Context) func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.ctx = v
}
}
// WithWaitForRemoval - specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list..
//
func (f ClusterDeleteVotingConfigExclusions) WithWaitForRemoval(v bool) func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.WaitForRemoval = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterDeleteVotingConfigExclusions) WithPretty() func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterDeleteVotingConfigExclusions) WithHuman() func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterDeleteVotingConfigExclusions) WithErrorTrace() func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterDeleteVotingConfigExclusions) WithFilterPath(v ...string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterDeleteVotingConfigExclusions) WithHeader(h map[string]string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterDeleteVotingConfigExclusions) WithOpaqueID(s string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,236 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterExistsComponentTemplateFunc(t Transport) ClusterExistsComponentTemplate {
return func(name string, o ...func(*ClusterExistsComponentTemplateRequest)) (*Response, error) {
var r = ClusterExistsComponentTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterExistsComponentTemplate returns information about whether a particular component template exist
//
//
type ClusterExistsComponentTemplate func(name string, o ...func(*ClusterExistsComponentTemplateRequest)) (*Response, error)
// ClusterExistsComponentTemplateRequest configures the Cluster Exists Component Template API request.
//
type ClusterExistsComponentTemplateRequest struct {
Name string
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 ClusterExistsComponentTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len("_component_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_component_template")
path.WriteString("/")
path.WriteString(r.Name)
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 ClusterExistsComponentTemplate) WithContext(v context.Context) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.ctx = v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f ClusterExistsComponentTemplate) WithLocal(v bool) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterExistsComponentTemplate) WithMasterTimeout(v time.Duration) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterExistsComponentTemplate) WithPretty() func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterExistsComponentTemplate) WithHuman() func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterExistsComponentTemplate) WithErrorTrace() func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterExistsComponentTemplate) WithFilterPath(v ...string) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterExistsComponentTemplate) WithHeader(h map[string]string) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterExistsComponentTemplate) WithOpaqueID(s string) func(*ClusterExistsComponentTemplateRequest) {
return func(r *ClusterExistsComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,246 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterGetComponentTemplateFunc(t Transport) ClusterGetComponentTemplate {
return func(o ...func(*ClusterGetComponentTemplateRequest)) (*Response, error) {
var r = ClusterGetComponentTemplateRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterGetComponentTemplate returns one or more component templates
//
//
type ClusterGetComponentTemplate func(o ...func(*ClusterGetComponentTemplateRequest)) (*Response, error)
// ClusterGetComponentTemplateRequest configures the Cluster Get Component Template API request.
//
type ClusterGetComponentTemplateRequest struct {
Name []string
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 ClusterGetComponentTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(1 + len("_component_template") + 1 + len(strings.Join(r.Name, ",")))
path.WriteString("/")
path.WriteString("_component_template")
if len(r.Name) > 0 {
path.WriteString("/")
path.WriteString(strings.Join(r.Name, ","))
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 ClusterGetComponentTemplate) WithContext(v context.Context) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.ctx = v
}
}
// WithName - the comma separated names of the component templates.
//
func (f ClusterGetComponentTemplate) WithName(v ...string) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.Name = v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f ClusterGetComponentTemplate) WithLocal(v bool) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f ClusterGetComponentTemplate) WithMasterTimeout(v time.Duration) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterGetComponentTemplate) WithPretty() func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterGetComponentTemplate) WithHuman() func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterGetComponentTemplate) WithErrorTrace() func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterGetComponentTemplate) WithFilterPath(v ...string) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterGetComponentTemplate) WithHeader(h map[string]string) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterGetComponentTemplate) WithOpaqueID(s string) func(*ClusterGetComponentTemplateRequest) {
return func(r *ClusterGetComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,257 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterGetSettings) WithOpaqueID(s string) func(*ClusterGetSettingsRequest) {
return func(r *ClusterGetSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,365 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
type ClusterHealth func(o ...func(*ClusterHealthRequest)) (*Response, error)
// ClusterHealthRequest configures the Cluster Health API request.
//
type ClusterHealthRequest struct {
Index []string
ExpandWildcards string
Level string
Local *bool
MasterTimeout time.Duration
Timeout time.Duration
WaitForActiveShards string
WaitForEvents string
WaitForNoInitializingShards *bool
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.ExpandWildcards != "" {
params["expand_wildcards"] = r.ExpandWildcards
}
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.WaitForNoInitializingShards != nil {
params["wait_for_no_initializing_shards"] = strconv.FormatBool(*r.WaitForNoInitializingShards)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f ClusterHealth) WithExpandWildcards(v string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.ExpandWildcards = 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
}
}
// WithWaitForNoInitializingShards - whether to wait until there are no initializing shards in the cluster.
//
func (f ClusterHealth) WithWaitForNoInitializingShards(v bool) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
r.WaitForNoInitializingShards = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterHealth) WithOpaqueID(s string) func(*ClusterHealthRequest) {
return func(r *ClusterHealthRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,232 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterPendingTasks) WithOpaqueID(s string) func(*ClusterPendingTasksRequest) {
return func(r *ClusterPendingTasksRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,243 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
"time"
)
func newClusterPostVotingConfigExclusionsFunc(t Transport) ClusterPostVotingConfigExclusions {
return func(o ...func(*ClusterPostVotingConfigExclusionsRequest)) (*Response, error) {
var r = ClusterPostVotingConfigExclusionsRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterPostVotingConfigExclusions updates the cluster voting config exclusions by node ids or node names.
//
//
type ClusterPostVotingConfigExclusions func(o ...func(*ClusterPostVotingConfigExclusionsRequest)) (*Response, error)
// ClusterPostVotingConfigExclusionsRequest configures the Cluster Post Voting Config Exclusions API request.
//
type ClusterPostVotingConfigExclusionsRequest struct {
NodeIds string
NodeNames string
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 ClusterPostVotingConfigExclusionsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(len("/_cluster/voting_config_exclusions"))
path.WriteString("/_cluster/voting_config_exclusions")
params = make(map[string]string)
if r.NodeIds != "" {
params["node_ids"] = r.NodeIds
}
if r.NodeNames != "" {
params["node_names"] = r.NodeNames
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 ClusterPostVotingConfigExclusions) WithContext(v context.Context) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.ctx = v
}
}
// WithNodeIds - a list of the persistent ids of the nodes to exclude from the voting configuration. if specified, you may not also specify ?node_names..
//
func (f ClusterPostVotingConfigExclusions) WithNodeIds(v string) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.NodeIds = v
}
}
// WithNodeNames - a list of the names of the nodes to exclude from the voting configuration. if specified, you may not also specify ?node_ids..
//
func (f ClusterPostVotingConfigExclusions) WithNodeNames(v string) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.NodeNames = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterPostVotingConfigExclusions) WithTimeout(v time.Duration) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterPostVotingConfigExclusions) WithPretty() func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterPostVotingConfigExclusions) WithHuman() func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterPostVotingConfigExclusions) WithErrorTrace() func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterPostVotingConfigExclusions) WithFilterPath(v ...string) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterPostVotingConfigExclusions) WithHeader(h map[string]string) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterPostVotingConfigExclusions) WithOpaqueID(s string) func(*ClusterPostVotingConfigExclusionsRequest) {
return func(r *ClusterPostVotingConfigExclusionsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,256 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterPutComponentTemplateFunc(t Transport) ClusterPutComponentTemplate {
return func(name string, body io.Reader, o ...func(*ClusterPutComponentTemplateRequest)) (*Response, error) {
var r = ClusterPutComponentTemplateRequest{Name: name, Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterPutComponentTemplate creates or updates a component template
//
//
type ClusterPutComponentTemplate func(name string, body io.Reader, o ...func(*ClusterPutComponentTemplateRequest)) (*Response, error)
// ClusterPutComponentTemplateRequest configures the Cluster Put Component Template API request.
//
type ClusterPutComponentTemplateRequest struct {
Body io.Reader
Name string
Create *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 ClusterPutComponentTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "PUT"
path.Grow(1 + len("_component_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_component_template")
path.WriteString("/")
path.WriteString(r.Name)
params = make(map[string]string)
if r.Create != nil {
params["create"] = strconv.FormatBool(*r.Create)
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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 ClusterPutComponentTemplate) WithContext(v context.Context) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.ctx = v
}
}
// WithCreate - whether the index template should only be added if new or can also replace an existing one.
//
func (f ClusterPutComponentTemplate) WithCreate(v bool) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.Create = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f ClusterPutComponentTemplate) WithMasterTimeout(v time.Duration) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f ClusterPutComponentTemplate) WithTimeout(v time.Duration) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f ClusterPutComponentTemplate) WithPretty() func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f ClusterPutComponentTemplate) WithHuman() func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f ClusterPutComponentTemplate) WithErrorTrace() func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f ClusterPutComponentTemplate) WithFilterPath(v ...string) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f ClusterPutComponentTemplate) WithHeader(h map[string]string) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterPutComponentTemplate) WithOpaqueID(s string) func(*ClusterPutComponentTemplateRequest) {
return func(r *ClusterPutComponentTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,251 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func newClusterPutSettingsFunc(t Transport) ClusterPutSettings {
return func(body io.Reader, o ...func(*ClusterPutSettingsRequest)) (*Response, error) {
var r = ClusterPutSettingsRequest{Body: body}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// ClusterPutSettings updates the cluster settings.
//
//
type ClusterPutSettings func(body io.Reader, 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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterPutSettings) WithOpaqueID(s string) func(*ClusterPutSettingsRequest) {
return func(r *ClusterPutSettingsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,202 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterRemoteInfo) WithOpaqueID(s string) func(*ClusterRemoteInfoRequest) {
return func(r *ClusterRemoteInfoRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,298 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterReroute) WithOpaqueID(s string) func(*ClusterRerouteRequest) {
return func(r *ClusterRerouteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,340 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
WaitForMetadataVersion *int
WaitForTimeout 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.WaitForMetadataVersion != nil {
params["wait_for_metadata_version"] = strconv.FormatInt(int64(*r.WaitForMetadataVersion), 10)
}
if r.WaitForTimeout != 0 {
params["wait_for_timeout"] = formatDuration(r.WaitForTimeout)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithWaitForMetadataVersion - wait for the metadata version to be equal or greater than the specified metadata version.
//
func (f ClusterState) WithWaitForMetadataVersion(v int) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.WaitForMetadataVersion = &v
}
}
// WithWaitForTimeout - the maximum time to wait for wait_for_metadata_version before timing out.
//
func (f ClusterState) WithWaitForTimeout(v time.Duration) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
r.WaitForTimeout = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterState) WithOpaqueID(s string) func(*ClusterStateRequest) {
return func(r *ClusterStateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,250 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ClusterStats) WithOpaqueID(s string) func(*ClusterStatsRequest) {
return func(r *ClusterStatsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,429 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
IgnoreThrottled *bool
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.IgnoreThrottled != nil {
params["ignore_throttled"] = strconv.FormatBool(*r.IgnoreThrottled)
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// WithIgnoreThrottled - whether specified concrete, expanded or aliased indices should be ignored when throttled.
//
func (f Count) WithIgnoreThrottled(v bool) func(*CountRequest) {
return func(r *CountRequest) {
r.IgnoreThrottled = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Count) WithOpaqueID(s string) func(*CountRequest) {
return func(r *CountRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,330 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Pipeline 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 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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_create")
params = make(map[string]string)
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.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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// 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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Create) WithOpaqueID(s string) func(*CreateRequest) {
return func(r *CreateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,249 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newDanglingIndicesDeleteDanglingIndexFunc(t Transport) DanglingIndicesDeleteDanglingIndex {
return func(index_uuid string, o ...func(*DanglingIndicesDeleteDanglingIndexRequest)) (*Response, error) {
var r = DanglingIndicesDeleteDanglingIndexRequest{IndexUUID: index_uuid}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DanglingIndicesDeleteDanglingIndex deletes the specified dangling index
//
//
type DanglingIndicesDeleteDanglingIndex func(index_uuid string, o ...func(*DanglingIndicesDeleteDanglingIndexRequest)) (*Response, error)
// DanglingIndicesDeleteDanglingIndexRequest configures the Dangling Indices Delete Dangling Index API request.
//
type DanglingIndicesDeleteDanglingIndexRequest struct {
IndexUUID string
AcceptDataLoss *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 DanglingIndicesDeleteDanglingIndexRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_dangling") + 1 + len(r.IndexUUID))
path.WriteString("/")
path.WriteString("_dangling")
path.WriteString("/")
path.WriteString(r.IndexUUID)
params = make(map[string]string)
if r.AcceptDataLoss != nil {
params["accept_data_loss"] = strconv.FormatBool(*r.AcceptDataLoss)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 DanglingIndicesDeleteDanglingIndex) WithContext(v context.Context) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.ctx = v
}
}
// WithAcceptDataLoss - must be set to true in order to delete the dangling index.
//
func (f DanglingIndicesDeleteDanglingIndex) WithAcceptDataLoss(v bool) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.AcceptDataLoss = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f DanglingIndicesDeleteDanglingIndex) WithMasterTimeout(v time.Duration) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f DanglingIndicesDeleteDanglingIndex) WithTimeout(v time.Duration) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DanglingIndicesDeleteDanglingIndex) WithPretty() func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DanglingIndicesDeleteDanglingIndex) WithHuman() func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DanglingIndicesDeleteDanglingIndex) WithErrorTrace() func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DanglingIndicesDeleteDanglingIndex) WithFilterPath(v ...string) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DanglingIndicesDeleteDanglingIndex) WithHeader(h map[string]string) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DanglingIndicesDeleteDanglingIndex) WithOpaqueID(s string) func(*DanglingIndicesDeleteDanglingIndexRequest) {
return func(r *DanglingIndicesDeleteDanglingIndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,249 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newDanglingIndicesImportDanglingIndexFunc(t Transport) DanglingIndicesImportDanglingIndex {
return func(index_uuid string, o ...func(*DanglingIndicesImportDanglingIndexRequest)) (*Response, error) {
var r = DanglingIndicesImportDanglingIndexRequest{IndexUUID: index_uuid}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DanglingIndicesImportDanglingIndex imports the specified dangling index
//
//
type DanglingIndicesImportDanglingIndex func(index_uuid string, o ...func(*DanglingIndicesImportDanglingIndexRequest)) (*Response, error)
// DanglingIndicesImportDanglingIndexRequest configures the Dangling Indices Import Dangling Index API request.
//
type DanglingIndicesImportDanglingIndexRequest struct {
IndexUUID string
AcceptDataLoss *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 DanglingIndicesImportDanglingIndexRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "POST"
path.Grow(1 + len("_dangling") + 1 + len(r.IndexUUID))
path.WriteString("/")
path.WriteString("_dangling")
path.WriteString("/")
path.WriteString(r.IndexUUID)
params = make(map[string]string)
if r.AcceptDataLoss != nil {
params["accept_data_loss"] = strconv.FormatBool(*r.AcceptDataLoss)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 DanglingIndicesImportDanglingIndex) WithContext(v context.Context) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.ctx = v
}
}
// WithAcceptDataLoss - must be set to true in order to import the dangling index.
//
func (f DanglingIndicesImportDanglingIndex) WithAcceptDataLoss(v bool) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.AcceptDataLoss = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f DanglingIndicesImportDanglingIndex) WithMasterTimeout(v time.Duration) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f DanglingIndicesImportDanglingIndex) WithTimeout(v time.Duration) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DanglingIndicesImportDanglingIndex) WithPretty() func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DanglingIndicesImportDanglingIndex) WithHuman() func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DanglingIndicesImportDanglingIndex) WithErrorTrace() func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DanglingIndicesImportDanglingIndex) WithFilterPath(v ...string) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DanglingIndicesImportDanglingIndex) WithHeader(h map[string]string) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DanglingIndicesImportDanglingIndex) WithOpaqueID(s string) func(*DanglingIndicesImportDanglingIndexRequest) {
return func(r *DanglingIndicesImportDanglingIndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,202 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
)
func newDanglingIndicesListDanglingIndicesFunc(t Transport) DanglingIndicesListDanglingIndices {
return func(o ...func(*DanglingIndicesListDanglingIndicesRequest)) (*Response, error) {
var r = DanglingIndicesListDanglingIndicesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DanglingIndicesListDanglingIndices returns all dangling indices.
//
//
type DanglingIndicesListDanglingIndices func(o ...func(*DanglingIndicesListDanglingIndicesRequest)) (*Response, error)
// DanglingIndicesListDanglingIndicesRequest configures the Dangling Indices List Dangling Indices API request.
//
type DanglingIndicesListDanglingIndicesRequest 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 DanglingIndicesListDanglingIndicesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_dangling"))
path.WriteString("/_dangling")
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 DanglingIndicesListDanglingIndices) WithContext(v context.Context) func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f DanglingIndicesListDanglingIndices) WithPretty() func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f DanglingIndicesListDanglingIndices) WithHuman() func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f DanglingIndicesListDanglingIndices) WithErrorTrace() func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f DanglingIndicesListDanglingIndices) WithFilterPath(v ...string) func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DanglingIndicesListDanglingIndices) WithHeader(h map[string]string) func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DanglingIndicesListDanglingIndices) WithOpaqueID(s string) func(*DanglingIndicesListDanglingIndicesRequest) {
return func(r *DanglingIndicesListDanglingIndicesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,332 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
IfPrimaryTerm *int
IfSeqNo *int
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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
if r.IfPrimaryTerm != nil {
params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10)
}
if r.IfSeqNo != nil {
params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithIfPrimaryTerm - only perform the delete operation if the last operation that has changed the document has the specified primary term.
//
func (f Delete) WithIfPrimaryTerm(v int) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.IfPrimaryTerm = &v
}
}
// WithIfSeqNo - only perform the delete operation if the last operation that has changed the document has the specified sequence number.
//
func (f Delete) WithIfSeqNo(v int) func(*DeleteRequest) {
return func(r *DeleteRequest) {
r.IfSeqNo = &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 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Delete) WithOpaqueID(s string) func(*DeleteRequest) {
return func(r *DeleteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,660 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"fmt"
"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.
//
//
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
MaxDocs *int
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 interface{}
Sort []string
Source []string
SourceExcludes []string
SourceIncludes []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.MaxDocs != nil {
params["max_docs"] = strconv.FormatInt(int64(*r.MaxDocs), 10)
}
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"] = fmt.Sprintf("%v", r.Slices)
}
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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// WithMaxDocs - maximum number of documents to process (default: all documents).
//
func (f DeleteByQuery) WithMaxDocs(v int) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.MaxDocs = &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 delete 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 - deprecated, please use `max_docs` instead.
//
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. can be set to `auto`..
//
func (f DeleteByQuery) WithSlices(v interface{}) 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f DeleteByQuery) WithSourceExcludes(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f DeleteByQuery) WithSourceIncludes(v ...string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DeleteByQuery) WithOpaqueID(s string) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,224 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"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.
//
//
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
Header http.Header
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 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
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f DeleteByQueryRethrottle) WithHeader(h map[string]string) func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DeleteByQueryRethrottle) WithOpaqueID(s string) func(*DeleteByQueryRethrottleRequest) {
return func(r *DeleteByQueryRethrottleRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,235 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
"time"
)
func newDeleteScriptFunc(t Transport) DeleteScript {
return func(id string, o ...func(*DeleteScriptRequest)) (*Response, error) {
var r = DeleteScriptRequest{ScriptID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// DeleteScript deletes a script.
//
//
type DeleteScript func(id string, o ...func(*DeleteScriptRequest)) (*Response, error)
// DeleteScriptRequest configures the Delete Script API request.
//
type DeleteScriptRequest struct {
ScriptID 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.ScriptID))
path.WriteString("/")
path.WriteString("_scripts")
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f DeleteScript) WithOpaqueID(s string) func(*DeleteScriptRequest) {
return func(r *DeleteScriptRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,357 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f Exists) WithSourceExcludes(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f Exists) WithSourceIncludes(v ...string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Exists) WithOpaqueID(s string) func(*ExistsRequest) {
return func(r *ExistsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,342 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_source")
params = make(map[string]string)
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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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; deprecated and optional starting with 7.0.
//
func (f ExistsSource) WithDocumentType(v string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.DocumentType = 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f ExistsSource) WithSourceExcludes(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f ExistsSource) WithSourceIncludes(v ...string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f ExistsSource) WithOpaqueID(s string) func(*ExistsSourceRequest) {
return func(r *ExistsSourceRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,400 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Preference string
Query string
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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 = "POST"
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)
if r.DocumentType != "" {
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.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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f Explain) WithSourceExcludes(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f Explain) WithSourceIncludes(v ...string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Explain) WithOpaqueID(s string) func(*ExplainRequest) {
return func(r *ExplainRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,299 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
IncludeUnmapped *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 = "POST"
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.IncludeUnmapped != nil {
params["include_unmapped"] = strconv.FormatBool(*r.IncludeUnmapped)
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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 - An index filter specified with the Query DSL.
//
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
}
}
// WithIncludeUnmapped - indicates whether unmapped fields should be included in the response..
//
func (f FieldCaps) WithIncludeUnmapped(v bool) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
r.IncludeUnmapped = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f FieldCaps) WithOpaqueID(s string) func(*FieldCapsRequest) {
return func(r *FieldCapsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,357 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
params = make(map[string]string)
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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f Get) WithSourceExcludes(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f Get) WithSourceIncludes(v ...string) func(*GetRequest) {
return func(r *GetRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Get) WithOpaqueID(s string) func(*GetRequest) {
return func(r *GetRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,222 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
"time"
)
func newGetScriptFunc(t Transport) GetScript {
return func(id string, o ...func(*GetScriptRequest)) (*Response, error) {
var r = GetScriptRequest{ScriptID: id}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// GetScript returns a script.
//
//
type GetScript func(id string, o ...func(*GetScriptRequest)) (*Response, error)
// GetScriptRequest configures the Get Script API request.
//
type GetScriptRequest struct {
ScriptID string
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 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.ScriptID))
path.WriteString("/")
path.WriteString("_scripts")
path.WriteString("/")
path.WriteString(r.ScriptID)
params = make(map[string]string)
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f GetScript) WithMasterTimeout(v time.Duration) func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
r.MasterTimeout = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f GetScript) WithOpaqueID(s string) func(*GetScriptRequest) {
return func(r *GetScriptRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,204 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
)
func newGetScriptContextFunc(t Transport) GetScriptContext {
return func(o ...func(*GetScriptContextRequest)) (*Response, error) {
var r = GetScriptContextRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// GetScriptContext returns all script contexts.
//
// This API is experimental.
//
//
type GetScriptContext func(o ...func(*GetScriptContextRequest)) (*Response, error)
// GetScriptContextRequest configures the Get Script Context API request.
//
type GetScriptContextRequest 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 GetScriptContextRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_script_context"))
path.WriteString("/_script_context")
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 GetScriptContext) WithContext(v context.Context) func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f GetScriptContext) WithPretty() func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f GetScriptContext) WithHuman() func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f GetScriptContext) WithErrorTrace() func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f GetScriptContext) WithFilterPath(v ...string) func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f GetScriptContext) WithHeader(h map[string]string) func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f GetScriptContext) WithOpaqueID(s string) func(*GetScriptContextRequest) {
return func(r *GetScriptContextRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,204 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
)
func newGetScriptLanguagesFunc(t Transport) GetScriptLanguages {
return func(o ...func(*GetScriptLanguagesRequest)) (*Response, error) {
var r = GetScriptLanguagesRequest{}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// GetScriptLanguages returns available script types, languages and contexts
//
// This API is experimental.
//
//
type GetScriptLanguages func(o ...func(*GetScriptLanguagesRequest)) (*Response, error)
// GetScriptLanguagesRequest configures the Get Script Languages API request.
//
type GetScriptLanguagesRequest 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 GetScriptLanguagesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "GET"
path.Grow(len("/_script_language"))
path.WriteString("/_script_language")
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 GetScriptLanguages) WithContext(v context.Context) func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
r.ctx = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f GetScriptLanguages) WithPretty() func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f GetScriptLanguages) WithHuman() func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f GetScriptLanguages) WithErrorTrace() func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f GetScriptLanguages) WithFilterPath(v ...string) func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f GetScriptLanguages) WithHeader(h map[string]string) func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f GetScriptLanguages) WithOpaqueID(s string) func(*GetScriptLanguagesRequest) {
return func(r *GetScriptLanguagesRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,346 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Preference string
Realtime *bool
Refresh *bool
Routing string
Source []string
SourceExcludes []string
SourceIncludes []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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
path.WriteString("/")
path.WriteString(r.DocumentID)
path.WriteString("/")
path.WriteString("_source")
params = make(map[string]string)
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.SourceExcludes) > 0 {
params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
}
if len(r.SourceIncludes) > 0 {
params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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; deprecated and optional starting with 7.0.
//
func (f GetSource) WithDocumentType(v string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.DocumentType = 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
}
}
// WithSourceExcludes - a list of fields to exclude from the returned _source field.
//
func (f GetSource) WithSourceExcludes(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.SourceExcludes = v
}
}
// WithSourceIncludes - a list of fields to extract and return from the _source field.
//
func (f GetSource) WithSourceIncludes(v ...string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
r.SourceIncludes = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f GetSource) WithOpaqueID(s string) func(*GetSourceRequest) {
return func(r *GetSourceRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,392 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
IfPrimaryTerm *int
IfSeqNo *int
OpType string
Pipeline string
Refresh string
RequireAlias *bool
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 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)
if r.DocumentType != "" {
path.WriteString("/")
path.WriteString(r.DocumentType)
}
if r.DocumentID != "" {
path.WriteString("/")
path.WriteString(r.DocumentID)
}
params = make(map[string]string)
if r.IfPrimaryTerm != nil {
params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10)
}
if r.IfSeqNo != nil {
params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10)
}
if r.OpType != "" {
params["op_type"] = r.OpType
}
if r.Pipeline != "" {
params["pipeline"] = r.Pipeline
}
if r.Refresh != "" {
params["refresh"] = r.Refresh
}
if r.RequireAlias != nil {
params["require_alias"] = strconv.FormatBool(*r.RequireAlias)
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// WithIfPrimaryTerm - only perform the index operation if the last operation that has changed the document has the specified primary term.
//
func (f Index) WithIfPrimaryTerm(v int) func(*IndexRequest) {
return func(r *IndexRequest) {
r.IfPrimaryTerm = &v
}
}
// WithIfSeqNo - only perform the index operation if the last operation that has changed the document has the specified sequence number.
//
func (f Index) WithIfSeqNo(v int) func(*IndexRequest) {
return func(r *IndexRequest) {
r.IfSeqNo = &v
}
}
// WithOpType - explicit operation type. defaults to `index` for requests with an explicit document ID, and to `create`for requests without an explicit document ID.
//
func (f Index) WithOpType(v string) func(*IndexRequest) {
return func(r *IndexRequest) {
r.OpType = 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
}
}
// WithRequireAlias - when true, requires destination to be an alias. default is false.
//
func (f Index) WithRequireAlias(v bool) func(*IndexRequest) {
return func(r *IndexRequest) {
r.RequireAlias = &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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Index) WithOpaqueID(s string) func(*IndexRequest) {
return func(r *IndexRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,279 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesAddBlockFunc(t Transport) IndicesAddBlock {
return func(index []string, block string, o ...func(*IndicesAddBlockRequest)) (*Response, error) {
var r = IndicesAddBlockRequest{Index: index, Block: block}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesAddBlock adds a block to an index.
//
//
type IndicesAddBlock func(index []string, block string, o ...func(*IndicesAddBlockRequest)) (*Response, error)
// IndicesAddBlockRequest configures the Indices Add Block API request.
//
type IndicesAddBlockRequest struct {
Index []string
Block 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 IndicesAddBlockRequest) 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("_block") + 1 + len(r.Block))
path.WriteString("/")
path.WriteString(strings.Join(r.Index, ","))
path.WriteString("/")
path.WriteString("_block")
path.WriteString("/")
path.WriteString(r.Block)
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 IndicesAddBlock) WithContext(v context.Context) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
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 IndicesAddBlock) WithAllowNoIndices(v bool) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesAddBlock) WithExpandWildcards(v string) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesAddBlock) WithIgnoreUnavailable(v bool) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.IgnoreUnavailable = &v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesAddBlock) WithMasterTimeout(v time.Duration) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesAddBlock) WithTimeout(v time.Duration) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesAddBlock) WithPretty() func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesAddBlock) WithHuman() func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesAddBlock) WithErrorTrace() func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesAddBlock) WithFilterPath(v ...string) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesAddBlock) WithHeader(h map[string]string) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesAddBlock) WithOpaqueID(s string) func(*IndicesAddBlockRequest) {
return func(r *IndicesAddBlockRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,236 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"io"
"net/http"
"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.
//
//
type IndicesAnalyze func(o ...func(*IndicesAnalyzeRequest)) (*Response, error)
// IndicesAnalyzeRequest configures the Indices Analyze API request.
//
type IndicesAnalyzeRequest struct {
Index string
Body io.Reader
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 = "POST"
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.Index != "" {
params["index"] = r.Index
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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 - Define analyzer/tokenizer parameters and 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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesAnalyze) WithOpaqueID(s string) func(*IndicesAnalyzeRequest) {
return func(r *IndicesAnalyzeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,316 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
Fields []string
IgnoreUnavailable *bool
Query *bool
Request *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 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.Request != nil {
params["request"] = strconv.FormatBool(*r.Request)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithFields - a list of fields to clear when using the `fielddata` 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
}
}
// WithRequest - clear request cache.
//
func (f IndicesClearCache) WithRequest(v bool) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
r.Request = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesClearCache) WithOpaqueID(s string) func(*IndicesClearCacheRequest) {
return func(r *IndicesClearCacheRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,267 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"io"
"net/http"
"strings"
"time"
)
func newIndicesCloneFunc(t Transport) IndicesClone {
return func(index string, target string, o ...func(*IndicesCloneRequest)) (*Response, error) {
var r = IndicesCloneRequest{Index: index, Target: target}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesClone clones an index
//
//
type IndicesClone func(index string, target string, o ...func(*IndicesCloneRequest)) (*Response, error)
// IndicesCloneRequest configures the Indices Clone API request.
//
type IndicesCloneRequest 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 IndicesCloneRequest) 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("_clone") + 1 + len(r.Target))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString("_clone")
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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 IndicesClone) WithContext(v context.Context) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.ctx = v
}
}
// WithBody - The configuration for the target index (`settings` and `aliases`).
//
func (f IndicesClone) WithBody(v io.Reader) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.Body = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesClone) WithMasterTimeout(v time.Duration) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesClone) WithTimeout(v time.Duration) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.Timeout = v
}
}
// WithWaitForActiveShards - set the number of active shards to wait for on the cloned index before the operation returns..
//
func (f IndicesClone) WithWaitForActiveShards(v string) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.WaitForActiveShards = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesClone) WithPretty() func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesClone) WithHuman() func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesClone) WithErrorTrace() func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesClone) WithFilterPath(v ...string) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesClone) WithHeader(h map[string]string) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesClone) WithOpaqueID(s string) func(*IndicesCloneRequest) {
return func(r *IndicesCloneRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,288 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
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 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.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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns. set to `index-setting` to wait according to the index setting `index.write.wait_for_active_shards`, or `all` to wait for all shards, or an integer. defaults to `0`..
//
func (f IndicesClose) WithWaitForActiveShards(v string) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
r.WaitForActiveShards = 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesClose) WithOpaqueID(s string) func(*IndicesCloseRequest) {
return func(r *IndicesCloseRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,275 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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
IncludeTypeName *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 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.IncludeTypeName != nil {
params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName)
}
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, err := newRequest(method, path.String(), r.Body)
if err != nil {
return nil, err
}
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
}
}
// WithIncludeTypeName - whether a type should be expected in the body of the mappings..
//
func (f IndicesCreate) WithIncludeTypeName(v bool) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
r.IncludeTypeName = &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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesCreate) WithOpaqueID(s string) func(*IndicesCreateRequest) {
return func(r *IndicesCreateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,273 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"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.
//
//
type IndicesDelete func(index []string, o ...func(*IndicesDeleteRequest)) (*Response, error)
// IndicesDeleteRequest configures the Indices Delete API request.
//
type IndicesDeleteRequest 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 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.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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false).
//
func (f IndicesDelete) WithAllowNoIndices(v bool) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open).
//
func (f IndicesDelete) WithExpandWildcards(v string) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.ExpandWildcards = v
}
}
// WithIgnoreUnavailable - ignore unavailable indexes (default: false).
//
func (f IndicesDelete) WithIgnoreUnavailable(v bool) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
r.IgnoreUnavailable = &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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesDelete) WithOpaqueID(s string) func(*IndicesDeleteRequest) {
return func(r *IndicesDeleteRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,239 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesDeleteAlias) WithOpaqueID(s string) func(*IndicesDeleteAliasRequest) {
return func(r *IndicesDeleteAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,235 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strings"
"time"
)
func newIndicesDeleteIndexTemplateFunc(t Transport) IndicesDeleteIndexTemplate {
return func(name string, o ...func(*IndicesDeleteIndexTemplateRequest)) (*Response, error) {
var r = IndicesDeleteIndexTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesDeleteIndexTemplate deletes an index template.
//
//
type IndicesDeleteIndexTemplate func(name string, o ...func(*IndicesDeleteIndexTemplateRequest)) (*Response, error)
// IndicesDeleteIndexTemplateRequest configures the Indices Delete Index Template API request.
//
type IndicesDeleteIndexTemplateRequest 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 IndicesDeleteIndexTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "DELETE"
path.Grow(1 + len("_index_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_index_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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 IndicesDeleteIndexTemplate) WithContext(v context.Context) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.ctx = v
}
}
// WithMasterTimeout - specify timeout for connection to master.
//
func (f IndicesDeleteIndexTemplate) WithMasterTimeout(v time.Duration) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.MasterTimeout = v
}
}
// WithTimeout - explicit operation timeout.
//
func (f IndicesDeleteIndexTemplate) WithTimeout(v time.Duration) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.Timeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesDeleteIndexTemplate) WithPretty() func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesDeleteIndexTemplate) WithHuman() func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesDeleteIndexTemplate) WithErrorTrace() func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesDeleteIndexTemplate) WithFilterPath(v ...string) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesDeleteIndexTemplate) WithHeader(h map[string]string) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesDeleteIndexTemplate) WithOpaqueID(s string) func(*IndicesDeleteIndexTemplateRequest) {
return func(r *IndicesDeleteIndexTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,235 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesDeleteTemplate) WithOpaqueID(s string) func(*IndicesDeleteTemplateRequest) {
return func(r *IndicesDeleteTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,276 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesDiskUsageFunc(t Transport) IndicesDiskUsage {
return func(index string, o ...func(*IndicesDiskUsageRequest)) (*Response, error) {
var r = IndicesDiskUsageRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesDiskUsage analyzes the disk usage of each field of an index or data stream
//
// This API is experimental.
//
//
type IndicesDiskUsage func(index string, o ...func(*IndicesDiskUsageRequest)) (*Response, error)
// IndicesDiskUsageRequest configures the Indices Disk Usage API request.
//
type IndicesDiskUsageRequest struct {
Index string
AllowNoIndices *bool
ExpandWildcards string
Flush *bool
IgnoreUnavailable *bool
RunExpensiveTasks *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 IndicesDiskUsageRequest) 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("_disk_usage"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString("_disk_usage")
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.RunExpensiveTasks != nil {
params["run_expensive_tasks"] = strconv.FormatBool(*r.RunExpensiveTasks)
}
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 IndicesDiskUsage) WithContext(v context.Context) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
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 IndicesDiskUsage) WithAllowNoIndices(v bool) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesDiskUsage) WithExpandWildcards(v string) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.ExpandWildcards = v
}
}
// WithFlush - whether flush or not before analyzing the index disk usage. defaults to true.
//
func (f IndicesDiskUsage) WithFlush(v bool) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.Flush = &v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesDiskUsage) WithIgnoreUnavailable(v bool) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.IgnoreUnavailable = &v
}
}
// WithRunExpensiveTasks - must be set to [true] in order for the task to be performed. defaults to false..
//
func (f IndicesDiskUsage) WithRunExpensiveTasks(v bool) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.RunExpensiveTasks = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesDiskUsage) WithPretty() func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesDiskUsage) WithHuman() func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesDiskUsage) WithErrorTrace() func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesDiskUsage) WithFilterPath(v ...string) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesDiskUsage) WithHeader(h map[string]string) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesDiskUsage) WithOpaqueID(s string) func(*IndicesDiskUsageRequest) {
return func(r *IndicesDiskUsageRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,285 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesExists) WithOpaqueID(s string) func(*IndicesExistsRequest) {
return func(r *IndicesExistsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,275 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesExistsAliasFunc(t Transport) IndicesExistsAlias {
return func(name []string, o ...func(*IndicesExistsAliasRequest)) (*Response, error) {
var r = IndicesExistsAliasRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExistsAlias returns information about whether a particular alias exists.
//
//
type IndicesExistsAlias func(name []string, 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")
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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
}
}
// 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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesExistsAlias) WithOpaqueID(s string) func(*IndicesExistsAliasRequest) {
return func(r *IndicesExistsAliasRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,249 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
"time"
)
func newIndicesExistsIndexTemplateFunc(t Transport) IndicesExistsIndexTemplate {
return func(name string, o ...func(*IndicesExistsIndexTemplateRequest)) (*Response, error) {
var r = IndicesExistsIndexTemplateRequest{Name: name}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesExistsIndexTemplate returns information about whether a particular index template exists.
//
//
type IndicesExistsIndexTemplate func(name string, o ...func(*IndicesExistsIndexTemplateRequest)) (*Response, error)
// IndicesExistsIndexTemplateRequest configures the Indices Exists Index Template API request.
//
type IndicesExistsIndexTemplateRequest 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 IndicesExistsIndexTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
path strings.Builder
params map[string]string
)
method = "HEAD"
path.Grow(1 + len("_index_template") + 1 + len(r.Name))
path.WriteString("/")
path.WriteString("_index_template")
path.WriteString("/")
path.WriteString(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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 IndicesExistsIndexTemplate) WithContext(v context.Context) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.ctx = v
}
}
// WithFlatSettings - return settings in flat format (default: false).
//
func (f IndicesExistsIndexTemplate) WithFlatSettings(v bool) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.FlatSettings = &v
}
}
// WithLocal - return local information, do not retrieve the state from master node (default: false).
//
func (f IndicesExistsIndexTemplate) WithLocal(v bool) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.Local = &v
}
}
// WithMasterTimeout - explicit operation timeout for connection to master node.
//
func (f IndicesExistsIndexTemplate) WithMasterTimeout(v time.Duration) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.MasterTimeout = v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesExistsIndexTemplate) WithPretty() func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesExistsIndexTemplate) WithHuman() func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesExistsIndexTemplate) WithErrorTrace() func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesExistsIndexTemplate) WithFilterPath(v ...string) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesExistsIndexTemplate) WithHeader(h map[string]string) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesExistsIndexTemplate) WithOpaqueID(s string) func(*IndicesExistsIndexTemplateRequest) {
return func(r *IndicesExistsIndexTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,249 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesExistsTemplate) WithOpaqueID(s string) func(*IndicesExistsTemplateRequest) {
return func(r *IndicesExistsTemplateRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,272 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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)
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesExistsDocumentType) WithOpaqueID(s string) func(*IndicesExistsDocumentTypeRequest) {
return func(r *IndicesExistsDocumentTypeRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,263 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
import (
"context"
"net/http"
"strconv"
"strings"
)
func newIndicesFieldUsageStatsFunc(t Transport) IndicesFieldUsageStats {
return func(index string, o ...func(*IndicesFieldUsageStatsRequest)) (*Response, error) {
var r = IndicesFieldUsageStatsRequest{Index: index}
for _, f := range o {
f(&r)
}
return r.Do(r.ctx, t)
}
}
// ----- API Definition -------------------------------------------------------
// IndicesFieldUsageStats returns the field usage stats for each field of an index
//
// This API is experimental.
//
//
type IndicesFieldUsageStats func(index string, o ...func(*IndicesFieldUsageStatsRequest)) (*Response, error)
// IndicesFieldUsageStatsRequest configures the Indices Field Usage Stats API request.
//
type IndicesFieldUsageStatsRequest struct {
Index string
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 IndicesFieldUsageStatsRequest) 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("_field_usage_stats"))
path.WriteString("/")
path.WriteString(r.Index)
path.WriteString("/")
path.WriteString("_field_usage_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.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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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 IndicesFieldUsageStats) WithContext(v context.Context) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
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 IndicesFieldUsageStats) WithAllowNoIndices(v bool) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.AllowNoIndices = &v
}
}
// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
//
func (f IndicesFieldUsageStats) WithExpandWildcards(v string) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.ExpandWildcards = v
}
}
// WithFields - a list of fields to include in the stats if only a subset of fields should be returned (supports wildcards).
//
func (f IndicesFieldUsageStats) WithFields(v ...string) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.Fields = v
}
}
// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
//
func (f IndicesFieldUsageStats) WithIgnoreUnavailable(v bool) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.IgnoreUnavailable = &v
}
}
// WithPretty makes the response body pretty-printed.
//
func (f IndicesFieldUsageStats) WithPretty() func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.Pretty = true
}
}
// WithHuman makes statistical values human-readable.
//
func (f IndicesFieldUsageStats) WithHuman() func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.Human = true
}
}
// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f IndicesFieldUsageStats) WithErrorTrace() func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.ErrorTrace = true
}
}
// WithFilterPath filters the properties of the response body.
//
func (f IndicesFieldUsageStats) WithFilterPath(v ...string) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
r.FilterPath = v
}
}
// WithHeader adds the headers to the HTTP request.
//
func (f IndicesFieldUsageStats) WithHeader(h map[string]string) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
for k, v := range h {
r.Header.Add(k, v)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesFieldUsageStats) WithOpaqueID(s string) func(*IndicesFieldUsageStatsRequest) {
return func(r *IndicesFieldUsageStatsRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,284 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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.
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesFlush) WithOpaqueID(s string) func(*IndicesFlushRequest) {
return func(r *IndicesFlushRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

View File

@@ -0,0 +1,260 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.
package opensearchapi
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. Synced flush is deprecated and will be removed in 8.0. Use flush instead
//
//
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, err := newRequest(method, path.String(), nil)
if err != nil {
return nil, err
}
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)
}
}
}
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f IndicesFlushSynced) WithOpaqueID(s string) func(*IndicesFlushSyncedRequest) {
return func(r *IndicesFlushSyncedRequest) {
if r.Header == nil {
r.Header = make(http.Header)
}
r.Header.Set("X-Opaque-Id", s)
}
}

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