api.xpack.indices.unfreeze.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 newIndicesUnfreezeFunc(t Transport) IndicesUnfreeze {
  28. return func(index string, o ...func(*IndicesUnfreezeRequest)) (*Response, error) {
  29. var r = IndicesUnfreezeRequest{Index: index}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // IndicesUnfreeze - Unfreezes an index. When a frozen index is unfrozen, the index goes through the normal recovery process and becomes writeable again.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/unfreeze-index-api.html.
  40. type IndicesUnfreeze func(index string, o ...func(*IndicesUnfreezeRequest)) (*Response, error)
  41. // IndicesUnfreezeRequest configures the Indices Unfreeze API request.
  42. type IndicesUnfreezeRequest struct {
  43. Index string
  44. AllowNoIndices *bool
  45. ExpandWildcards string
  46. IgnoreUnavailable *bool
  47. MasterTimeout time.Duration
  48. Timeout time.Duration
  49. WaitForActiveShards string
  50. Pretty bool
  51. Human bool
  52. ErrorTrace bool
  53. FilterPath []string
  54. Header http.Header
  55. ctx context.Context
  56. }
  57. // Do executes the request and returns response or error.
  58. func (r IndicesUnfreezeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  59. var (
  60. method string
  61. path strings.Builder
  62. params map[string]string
  63. )
  64. method = "POST"
  65. path.Grow(1 + len(r.Index) + 1 + len("_unfreeze"))
  66. path.WriteString("/")
  67. path.WriteString(r.Index)
  68. path.WriteString("/")
  69. path.WriteString("_unfreeze")
  70. params = make(map[string]string)
  71. if r.AllowNoIndices != nil {
  72. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  73. }
  74. if r.ExpandWildcards != "" {
  75. params["expand_wildcards"] = r.ExpandWildcards
  76. }
  77. if r.IgnoreUnavailable != nil {
  78. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  79. }
  80. if r.MasterTimeout != 0 {
  81. params["master_timeout"] = formatDuration(r.MasterTimeout)
  82. }
  83. if r.Timeout != 0 {
  84. params["timeout"] = formatDuration(r.Timeout)
  85. }
  86. if r.WaitForActiveShards != "" {
  87. params["wait_for_active_shards"] = r.WaitForActiveShards
  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 IndicesUnfreeze) WithContext(v context.Context) func(*IndicesUnfreezeRequest) {
  139. return func(r *IndicesUnfreezeRequest) {
  140. r.ctx = v
  141. }
  142. }
  143. // 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).
  144. func (f IndicesUnfreeze) WithAllowNoIndices(v bool) func(*IndicesUnfreezeRequest) {
  145. return func(r *IndicesUnfreezeRequest) {
  146. r.AllowNoIndices = &v
  147. }
  148. }
  149. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  150. func (f IndicesUnfreeze) WithExpandWildcards(v string) func(*IndicesUnfreezeRequest) {
  151. return func(r *IndicesUnfreezeRequest) {
  152. r.ExpandWildcards = v
  153. }
  154. }
  155. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  156. func (f IndicesUnfreeze) WithIgnoreUnavailable(v bool) func(*IndicesUnfreezeRequest) {
  157. return func(r *IndicesUnfreezeRequest) {
  158. r.IgnoreUnavailable = &v
  159. }
  160. }
  161. // WithMasterTimeout - specify timeout for connection to master.
  162. func (f IndicesUnfreeze) WithMasterTimeout(v time.Duration) func(*IndicesUnfreezeRequest) {
  163. return func(r *IndicesUnfreezeRequest) {
  164. r.MasterTimeout = v
  165. }
  166. }
  167. // WithTimeout - explicit operation timeout.
  168. func (f IndicesUnfreeze) WithTimeout(v time.Duration) func(*IndicesUnfreezeRequest) {
  169. return func(r *IndicesUnfreezeRequest) {
  170. r.Timeout = v
  171. }
  172. }
  173. // WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns..
  174. func (f IndicesUnfreeze) WithWaitForActiveShards(v string) func(*IndicesUnfreezeRequest) {
  175. return func(r *IndicesUnfreezeRequest) {
  176. r.WaitForActiveShards = v
  177. }
  178. }
  179. // WithPretty makes the response body pretty-printed.
  180. func (f IndicesUnfreeze) WithPretty() func(*IndicesUnfreezeRequest) {
  181. return func(r *IndicesUnfreezeRequest) {
  182. r.Pretty = true
  183. }
  184. }
  185. // WithHuman makes statistical values human-readable.
  186. func (f IndicesUnfreeze) WithHuman() func(*IndicesUnfreezeRequest) {
  187. return func(r *IndicesUnfreezeRequest) {
  188. r.Human = true
  189. }
  190. }
  191. // WithErrorTrace includes the stack trace for errors in the response body.
  192. func (f IndicesUnfreeze) WithErrorTrace() func(*IndicesUnfreezeRequest) {
  193. return func(r *IndicesUnfreezeRequest) {
  194. r.ErrorTrace = true
  195. }
  196. }
  197. // WithFilterPath filters the properties of the response body.
  198. func (f IndicesUnfreeze) WithFilterPath(v ...string) func(*IndicesUnfreezeRequest) {
  199. return func(r *IndicesUnfreezeRequest) {
  200. r.FilterPath = v
  201. }
  202. }
  203. // WithHeader adds the headers to the HTTP request.
  204. func (f IndicesUnfreeze) WithHeader(h map[string]string) func(*IndicesUnfreezeRequest) {
  205. return func(r *IndicesUnfreezeRequest) {
  206. if r.Header == nil {
  207. r.Header = make(http.Header)
  208. }
  209. for k, v := range h {
  210. r.Header.Add(k, v)
  211. }
  212. }
  213. }
  214. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  215. func (f IndicesUnfreeze) WithOpaqueID(s string) func(*IndicesUnfreezeRequest) {
  216. return func(r *IndicesUnfreezeRequest) {
  217. if r.Header == nil {
  218. r.Header = make(http.Header)
  219. }
  220. r.Header.Set("X-Opaque-Id", s)
  221. }
  222. }