api.indices.put_settings.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. "io"
  23. "net/http"
  24. "strconv"
  25. "strings"
  26. "time"
  27. )
  28. func newIndicesPutSettingsFunc(t Transport) IndicesPutSettings {
  29. return func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error) {
  30. var r = IndicesPutSettingsRequest{Body: body}
  31. for _, f := range o {
  32. f(&r)
  33. }
  34. return r.Do(r.ctx, t)
  35. }
  36. }
  37. // ----- API Definition -------------------------------------------------------
  38. // IndicesPutSettings updates the index settings.
  39. //
  40. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html.
  41. type IndicesPutSettings func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error)
  42. // IndicesPutSettingsRequest configures the Indices Put Settings API request.
  43. type IndicesPutSettingsRequest struct {
  44. Index []string
  45. Body io.Reader
  46. AllowNoIndices *bool
  47. ExpandWildcards string
  48. FlatSettings *bool
  49. IgnoreUnavailable *bool
  50. MasterTimeout time.Duration
  51. PreserveExisting *bool
  52. Timeout time.Duration
  53. Pretty bool
  54. Human bool
  55. ErrorTrace bool
  56. FilterPath []string
  57. Header http.Header
  58. ctx context.Context
  59. }
  60. // Do executes the request and returns response or error.
  61. func (r IndicesPutSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  62. var (
  63. method string
  64. path strings.Builder
  65. params map[string]string
  66. )
  67. method = "PUT"
  68. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings"))
  69. if len(r.Index) > 0 {
  70. path.WriteString("/")
  71. path.WriteString(strings.Join(r.Index, ","))
  72. }
  73. path.WriteString("/")
  74. path.WriteString("_settings")
  75. params = make(map[string]string)
  76. if r.AllowNoIndices != nil {
  77. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  78. }
  79. if r.ExpandWildcards != "" {
  80. params["expand_wildcards"] = r.ExpandWildcards
  81. }
  82. if r.FlatSettings != nil {
  83. params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
  84. }
  85. if r.IgnoreUnavailable != nil {
  86. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  87. }
  88. if r.MasterTimeout != 0 {
  89. params["master_timeout"] = formatDuration(r.MasterTimeout)
  90. }
  91. if r.PreserveExisting != nil {
  92. params["preserve_existing"] = strconv.FormatBool(*r.PreserveExisting)
  93. }
  94. if r.Timeout != 0 {
  95. params["timeout"] = formatDuration(r.Timeout)
  96. }
  97. if r.Pretty {
  98. params["pretty"] = "true"
  99. }
  100. if r.Human {
  101. params["human"] = "true"
  102. }
  103. if r.ErrorTrace {
  104. params["error_trace"] = "true"
  105. }
  106. if len(r.FilterPath) > 0 {
  107. params["filter_path"] = strings.Join(r.FilterPath, ",")
  108. }
  109. req, err := newRequest(method, path.String(), r.Body)
  110. if err != nil {
  111. return nil, err
  112. }
  113. if len(params) > 0 {
  114. q := req.URL.Query()
  115. for k, v := range params {
  116. q.Set(k, v)
  117. }
  118. req.URL.RawQuery = q.Encode()
  119. }
  120. if len(r.Header) > 0 {
  121. if len(req.Header) == 0 {
  122. req.Header = r.Header
  123. } else {
  124. for k, vv := range r.Header {
  125. for _, v := range vv {
  126. req.Header.Add(k, v)
  127. }
  128. }
  129. }
  130. }
  131. if r.Body != nil && req.Header.Get(headerContentType) == "" {
  132. req.Header[headerContentType] = headerContentTypeJSON
  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 IndicesPutSettings) WithContext(v context.Context) func(*IndicesPutSettingsRequest) {
  150. return func(r *IndicesPutSettingsRequest) {
  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 IndicesPutSettings) WithIndex(v ...string) func(*IndicesPutSettingsRequest) {
  156. return func(r *IndicesPutSettingsRequest) {
  157. r.Index = v
  158. }
  159. }
  160. // 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).
  161. func (f IndicesPutSettings) WithAllowNoIndices(v bool) func(*IndicesPutSettingsRequest) {
  162. return func(r *IndicesPutSettingsRequest) {
  163. r.AllowNoIndices = &v
  164. }
  165. }
  166. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  167. func (f IndicesPutSettings) WithExpandWildcards(v string) func(*IndicesPutSettingsRequest) {
  168. return func(r *IndicesPutSettingsRequest) {
  169. r.ExpandWildcards = v
  170. }
  171. }
  172. // WithFlatSettings - return settings in flat format (default: false).
  173. func (f IndicesPutSettings) WithFlatSettings(v bool) func(*IndicesPutSettingsRequest) {
  174. return func(r *IndicesPutSettingsRequest) {
  175. r.FlatSettings = &v
  176. }
  177. }
  178. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  179. func (f IndicesPutSettings) WithIgnoreUnavailable(v bool) func(*IndicesPutSettingsRequest) {
  180. return func(r *IndicesPutSettingsRequest) {
  181. r.IgnoreUnavailable = &v
  182. }
  183. }
  184. // WithMasterTimeout - specify timeout for connection to master.
  185. func (f IndicesPutSettings) WithMasterTimeout(v time.Duration) func(*IndicesPutSettingsRequest) {
  186. return func(r *IndicesPutSettingsRequest) {
  187. r.MasterTimeout = v
  188. }
  189. }
  190. // WithPreserveExisting - whether to update existing settings. if set to `true` existing settings on an index remain unchanged, the default is `false`.
  191. func (f IndicesPutSettings) WithPreserveExisting(v bool) func(*IndicesPutSettingsRequest) {
  192. return func(r *IndicesPutSettingsRequest) {
  193. r.PreserveExisting = &v
  194. }
  195. }
  196. // WithTimeout - explicit operation timeout.
  197. func (f IndicesPutSettings) WithTimeout(v time.Duration) func(*IndicesPutSettingsRequest) {
  198. return func(r *IndicesPutSettingsRequest) {
  199. r.Timeout = v
  200. }
  201. }
  202. // WithPretty makes the response body pretty-printed.
  203. func (f IndicesPutSettings) WithPretty() func(*IndicesPutSettingsRequest) {
  204. return func(r *IndicesPutSettingsRequest) {
  205. r.Pretty = true
  206. }
  207. }
  208. // WithHuman makes statistical values human-readable.
  209. func (f IndicesPutSettings) WithHuman() func(*IndicesPutSettingsRequest) {
  210. return func(r *IndicesPutSettingsRequest) {
  211. r.Human = true
  212. }
  213. }
  214. // WithErrorTrace includes the stack trace for errors in the response body.
  215. func (f IndicesPutSettings) WithErrorTrace() func(*IndicesPutSettingsRequest) {
  216. return func(r *IndicesPutSettingsRequest) {
  217. r.ErrorTrace = true
  218. }
  219. }
  220. // WithFilterPath filters the properties of the response body.
  221. func (f IndicesPutSettings) WithFilterPath(v ...string) func(*IndicesPutSettingsRequest) {
  222. return func(r *IndicesPutSettingsRequest) {
  223. r.FilterPath = v
  224. }
  225. }
  226. // WithHeader adds the headers to the HTTP request.
  227. func (f IndicesPutSettings) WithHeader(h map[string]string) func(*IndicesPutSettingsRequest) {
  228. return func(r *IndicesPutSettingsRequest) {
  229. if r.Header == nil {
  230. r.Header = make(http.Header)
  231. }
  232. for k, v := range h {
  233. r.Header.Add(k, v)
  234. }
  235. }
  236. }
  237. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  238. func (f IndicesPutSettings) WithOpaqueID(s string) func(*IndicesPutSettingsRequest) {
  239. return func(r *IndicesPutSettingsRequest) {
  240. if r.Header == nil {
  241. r.Header = make(http.Header)
  242. }
  243. r.Header.Set("X-Opaque-Id", s)
  244. }
  245. }