api.indices.exists_alias.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. // Code generated from specification version 7.17.10: DO NOT EDIT
  19. package esapi
  20. import (
  21. "context"
  22. "errors"
  23. "net/http"
  24. "strconv"
  25. "strings"
  26. )
  27. func newIndicesExistsAliasFunc(t Transport) IndicesExistsAlias {
  28. return func(name []string, o ...func(*IndicesExistsAliasRequest)) (*Response, error) {
  29. var r = IndicesExistsAliasRequest{Name: name}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // IndicesExistsAlias returns information about whether a particular alias exists.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html.
  40. type IndicesExistsAlias func(name []string, o ...func(*IndicesExistsAliasRequest)) (*Response, error)
  41. // IndicesExistsAliasRequest configures the Indices Exists Alias API request.
  42. type IndicesExistsAliasRequest struct {
  43. Index []string
  44. Name []string
  45. AllowNoIndices *bool
  46. ExpandWildcards string
  47. IgnoreUnavailable *bool
  48. Local *bool
  49. Pretty bool
  50. Human bool
  51. ErrorTrace bool
  52. FilterPath []string
  53. Header http.Header
  54. ctx context.Context
  55. }
  56. // Do executes the request and returns response or error.
  57. func (r IndicesExistsAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  58. var (
  59. method string
  60. path strings.Builder
  61. params map[string]string
  62. )
  63. method = "HEAD"
  64. if len(r.Name) == 0 {
  65. return nil, errors.New("name is required and cannot be nil or empty")
  66. }
  67. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ",")))
  68. if len(r.Index) > 0 {
  69. path.WriteString("/")
  70. path.WriteString(strings.Join(r.Index, ","))
  71. }
  72. path.WriteString("/")
  73. path.WriteString("_alias")
  74. path.WriteString("/")
  75. path.WriteString(strings.Join(r.Name, ","))
  76. params = make(map[string]string)
  77. if r.AllowNoIndices != nil {
  78. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  79. }
  80. if r.ExpandWildcards != "" {
  81. params["expand_wildcards"] = r.ExpandWildcards
  82. }
  83. if r.IgnoreUnavailable != nil {
  84. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  85. }
  86. if r.Local != nil {
  87. params["local"] = strconv.FormatBool(*r.Local)
  88. }
  89. if r.Pretty {
  90. params["pretty"] = "true"
  91. }
  92. if r.Human {
  93. params["human"] = "true"
  94. }
  95. if r.ErrorTrace {
  96. params["error_trace"] = "true"
  97. }
  98. if len(r.FilterPath) > 0 {
  99. params["filter_path"] = strings.Join(r.FilterPath, ",")
  100. }
  101. req, err := newRequest(method, path.String(), nil)
  102. if err != nil {
  103. return nil, err
  104. }
  105. if len(params) > 0 {
  106. q := req.URL.Query()
  107. for k, v := range params {
  108. q.Set(k, v)
  109. }
  110. req.URL.RawQuery = q.Encode()
  111. }
  112. if len(r.Header) > 0 {
  113. if len(req.Header) == 0 {
  114. req.Header = r.Header
  115. } else {
  116. for k, vv := range r.Header {
  117. for _, v := range vv {
  118. req.Header.Add(k, v)
  119. }
  120. }
  121. }
  122. }
  123. if ctx != nil {
  124. req = req.WithContext(ctx)
  125. }
  126. res, err := transport.Perform(req)
  127. if err != nil {
  128. return nil, err
  129. }
  130. response := Response{
  131. StatusCode: res.StatusCode,
  132. Body: res.Body,
  133. Header: res.Header,
  134. }
  135. return &response, nil
  136. }
  137. // WithContext sets the request context.
  138. func (f IndicesExistsAlias) WithContext(v context.Context) func(*IndicesExistsAliasRequest) {
  139. return func(r *IndicesExistsAliasRequest) {
  140. r.ctx = v
  141. }
  142. }
  143. // WithIndex - a list of index names to filter aliases.
  144. func (f IndicesExistsAlias) WithIndex(v ...string) func(*IndicesExistsAliasRequest) {
  145. return func(r *IndicesExistsAliasRequest) {
  146. r.Index = v
  147. }
  148. }
  149. // 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).
  150. func (f IndicesExistsAlias) WithAllowNoIndices(v bool) func(*IndicesExistsAliasRequest) {
  151. return func(r *IndicesExistsAliasRequest) {
  152. r.AllowNoIndices = &v
  153. }
  154. }
  155. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  156. func (f IndicesExistsAlias) WithExpandWildcards(v string) func(*IndicesExistsAliasRequest) {
  157. return func(r *IndicesExistsAliasRequest) {
  158. r.ExpandWildcards = v
  159. }
  160. }
  161. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  162. func (f IndicesExistsAlias) WithIgnoreUnavailable(v bool) func(*IndicesExistsAliasRequest) {
  163. return func(r *IndicesExistsAliasRequest) {
  164. r.IgnoreUnavailable = &v
  165. }
  166. }
  167. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  168. func (f IndicesExistsAlias) WithLocal(v bool) func(*IndicesExistsAliasRequest) {
  169. return func(r *IndicesExistsAliasRequest) {
  170. r.Local = &v
  171. }
  172. }
  173. // WithPretty makes the response body pretty-printed.
  174. func (f IndicesExistsAlias) WithPretty() func(*IndicesExistsAliasRequest) {
  175. return func(r *IndicesExistsAliasRequest) {
  176. r.Pretty = true
  177. }
  178. }
  179. // WithHuman makes statistical values human-readable.
  180. func (f IndicesExistsAlias) WithHuman() func(*IndicesExistsAliasRequest) {
  181. return func(r *IndicesExistsAliasRequest) {
  182. r.Human = true
  183. }
  184. }
  185. // WithErrorTrace includes the stack trace for errors in the response body.
  186. func (f IndicesExistsAlias) WithErrorTrace() func(*IndicesExistsAliasRequest) {
  187. return func(r *IndicesExistsAliasRequest) {
  188. r.ErrorTrace = true
  189. }
  190. }
  191. // WithFilterPath filters the properties of the response body.
  192. func (f IndicesExistsAlias) WithFilterPath(v ...string) func(*IndicesExistsAliasRequest) {
  193. return func(r *IndicesExistsAliasRequest) {
  194. r.FilterPath = v
  195. }
  196. }
  197. // WithHeader adds the headers to the HTTP request.
  198. func (f IndicesExistsAlias) WithHeader(h map[string]string) func(*IndicesExistsAliasRequest) {
  199. return func(r *IndicesExistsAliasRequest) {
  200. if r.Header == nil {
  201. r.Header = make(http.Header)
  202. }
  203. for k, v := range h {
  204. r.Header.Add(k, v)
  205. }
  206. }
  207. }
  208. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  209. func (f IndicesExistsAlias) WithOpaqueID(s string) func(*IndicesExistsAliasRequest) {
  210. return func(r *IndicesExistsAliasRequest) {
  211. if r.Header == nil {
  212. r.Header = make(http.Header)
  213. }
  214. r.Header.Set("X-Opaque-Id", s)
  215. }
  216. }