api.indices.get_alias.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. "net/http"
  23. "strconv"
  24. "strings"
  25. )
  26. func newIndicesGetAliasFunc(t Transport) IndicesGetAlias {
  27. return func(o ...func(*IndicesGetAliasRequest)) (*Response, error) {
  28. var r = IndicesGetAliasRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // IndicesGetAlias returns an alias.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html.
  39. type IndicesGetAlias func(o ...func(*IndicesGetAliasRequest)) (*Response, error)
  40. // IndicesGetAliasRequest configures the Indices Get Alias API request.
  41. type IndicesGetAliasRequest struct {
  42. Index []string
  43. Name []string
  44. AllowNoIndices *bool
  45. ExpandWildcards string
  46. IgnoreUnavailable *bool
  47. Local *bool
  48. Pretty bool
  49. Human bool
  50. ErrorTrace bool
  51. FilterPath []string
  52. Header http.Header
  53. ctx context.Context
  54. }
  55. // Do executes the request and returns response or error.
  56. func (r IndicesGetAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  57. var (
  58. method string
  59. path strings.Builder
  60. params map[string]string
  61. )
  62. method = "GET"
  63. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ",")))
  64. if len(r.Index) > 0 {
  65. path.WriteString("/")
  66. path.WriteString(strings.Join(r.Index, ","))
  67. }
  68. path.WriteString("/")
  69. path.WriteString("_alias")
  70. if len(r.Name) > 0 {
  71. path.WriteString("/")
  72. path.WriteString(strings.Join(r.Name, ","))
  73. }
  74. params = make(map[string]string)
  75. if r.AllowNoIndices != nil {
  76. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  77. }
  78. if r.ExpandWildcards != "" {
  79. params["expand_wildcards"] = r.ExpandWildcards
  80. }
  81. if r.IgnoreUnavailable != nil {
  82. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  83. }
  84. if r.Local != nil {
  85. params["local"] = strconv.FormatBool(*r.Local)
  86. }
  87. if r.Pretty {
  88. params["pretty"] = "true"
  89. }
  90. if r.Human {
  91. params["human"] = "true"
  92. }
  93. if r.ErrorTrace {
  94. params["error_trace"] = "true"
  95. }
  96. if len(r.FilterPath) > 0 {
  97. params["filter_path"] = strings.Join(r.FilterPath, ",")
  98. }
  99. req, err := newRequest(method, path.String(), nil)
  100. if err != nil {
  101. return nil, err
  102. }
  103. if len(params) > 0 {
  104. q := req.URL.Query()
  105. for k, v := range params {
  106. q.Set(k, v)
  107. }
  108. req.URL.RawQuery = q.Encode()
  109. }
  110. if len(r.Header) > 0 {
  111. if len(req.Header) == 0 {
  112. req.Header = r.Header
  113. } else {
  114. for k, vv := range r.Header {
  115. for _, v := range vv {
  116. req.Header.Add(k, v)
  117. }
  118. }
  119. }
  120. }
  121. if ctx != nil {
  122. req = req.WithContext(ctx)
  123. }
  124. res, err := transport.Perform(req)
  125. if err != nil {
  126. return nil, err
  127. }
  128. response := Response{
  129. StatusCode: res.StatusCode,
  130. Body: res.Body,
  131. Header: res.Header,
  132. }
  133. return &response, nil
  134. }
  135. // WithContext sets the request context.
  136. func (f IndicesGetAlias) WithContext(v context.Context) func(*IndicesGetAliasRequest) {
  137. return func(r *IndicesGetAliasRequest) {
  138. r.ctx = v
  139. }
  140. }
  141. // WithIndex - a list of index names to filter aliases.
  142. func (f IndicesGetAlias) WithIndex(v ...string) func(*IndicesGetAliasRequest) {
  143. return func(r *IndicesGetAliasRequest) {
  144. r.Index = v
  145. }
  146. }
  147. // WithName - a list of alias names to return.
  148. func (f IndicesGetAlias) WithName(v ...string) func(*IndicesGetAliasRequest) {
  149. return func(r *IndicesGetAliasRequest) {
  150. r.Name = v
  151. }
  152. }
  153. // 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).
  154. func (f IndicesGetAlias) WithAllowNoIndices(v bool) func(*IndicesGetAliasRequest) {
  155. return func(r *IndicesGetAliasRequest) {
  156. r.AllowNoIndices = &v
  157. }
  158. }
  159. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  160. func (f IndicesGetAlias) WithExpandWildcards(v string) func(*IndicesGetAliasRequest) {
  161. return func(r *IndicesGetAliasRequest) {
  162. r.ExpandWildcards = v
  163. }
  164. }
  165. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  166. func (f IndicesGetAlias) WithIgnoreUnavailable(v bool) func(*IndicesGetAliasRequest) {
  167. return func(r *IndicesGetAliasRequest) {
  168. r.IgnoreUnavailable = &v
  169. }
  170. }
  171. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  172. func (f IndicesGetAlias) WithLocal(v bool) func(*IndicesGetAliasRequest) {
  173. return func(r *IndicesGetAliasRequest) {
  174. r.Local = &v
  175. }
  176. }
  177. // WithPretty makes the response body pretty-printed.
  178. func (f IndicesGetAlias) WithPretty() func(*IndicesGetAliasRequest) {
  179. return func(r *IndicesGetAliasRequest) {
  180. r.Pretty = true
  181. }
  182. }
  183. // WithHuman makes statistical values human-readable.
  184. func (f IndicesGetAlias) WithHuman() func(*IndicesGetAliasRequest) {
  185. return func(r *IndicesGetAliasRequest) {
  186. r.Human = true
  187. }
  188. }
  189. // WithErrorTrace includes the stack trace for errors in the response body.
  190. func (f IndicesGetAlias) WithErrorTrace() func(*IndicesGetAliasRequest) {
  191. return func(r *IndicesGetAliasRequest) {
  192. r.ErrorTrace = true
  193. }
  194. }
  195. // WithFilterPath filters the properties of the response body.
  196. func (f IndicesGetAlias) WithFilterPath(v ...string) func(*IndicesGetAliasRequest) {
  197. return func(r *IndicesGetAliasRequest) {
  198. r.FilterPath = v
  199. }
  200. }
  201. // WithHeader adds the headers to the HTTP request.
  202. func (f IndicesGetAlias) WithHeader(h map[string]string) func(*IndicesGetAliasRequest) {
  203. return func(r *IndicesGetAliasRequest) {
  204. if r.Header == nil {
  205. r.Header = make(http.Header)
  206. }
  207. for k, v := range h {
  208. r.Header.Add(k, v)
  209. }
  210. }
  211. }
  212. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  213. func (f IndicesGetAlias) WithOpaqueID(s string) func(*IndicesGetAliasRequest) {
  214. return func(r *IndicesGetAliasRequest) {
  215. if r.Header == nil {
  216. r.Header = make(http.Header)
  217. }
  218. r.Header.Set("X-Opaque-Id", s)
  219. }
  220. }