api.indices.get_settings.go 8.0 KB

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