api.indices.refresh.go 6.1 KB

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