api.indices.flush.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 newIndicesFlushFunc(t Transport) IndicesFlush {
  27. return func(o ...func(*IndicesFlushRequest)) (*Response, error) {
  28. var r = IndicesFlushRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // IndicesFlush performs the flush operation on one or more indices.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html.
  39. type IndicesFlush func(o ...func(*IndicesFlushRequest)) (*Response, error)
  40. // IndicesFlushRequest configures the Indices Flush API request.
  41. type IndicesFlushRequest struct {
  42. Index []string
  43. AllowNoIndices *bool
  44. ExpandWildcards string
  45. Force *bool
  46. IgnoreUnavailable *bool
  47. WaitIfOngoing *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 IndicesFlushRequest) 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 = "POST"
  63. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_flush"))
  64. if len(r.Index) > 0 {
  65. path.WriteString("/")
  66. path.WriteString(strings.Join(r.Index, ","))
  67. }
  68. path.WriteString("/")
  69. path.WriteString("_flush")
  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.Force != nil {
  78. params["force"] = strconv.FormatBool(*r.Force)
  79. }
  80. if r.IgnoreUnavailable != nil {
  81. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  82. }
  83. if r.WaitIfOngoing != nil {
  84. params["wait_if_ongoing"] = strconv.FormatBool(*r.WaitIfOngoing)
  85. }
  86. if r.Pretty {
  87. params["pretty"] = "true"
  88. }
  89. if r.Human {
  90. params["human"] = "true"
  91. }
  92. if r.ErrorTrace {
  93. params["error_trace"] = "true"
  94. }
  95. if len(r.FilterPath) > 0 {
  96. params["filter_path"] = strings.Join(r.FilterPath, ",")
  97. }
  98. req, err := newRequest(method, path.String(), nil)
  99. if err != nil {
  100. return nil, err
  101. }
  102. if len(params) > 0 {
  103. q := req.URL.Query()
  104. for k, v := range params {
  105. q.Set(k, v)
  106. }
  107. req.URL.RawQuery = q.Encode()
  108. }
  109. if len(r.Header) > 0 {
  110. if len(req.Header) == 0 {
  111. req.Header = r.Header
  112. } else {
  113. for k, vv := range r.Header {
  114. for _, v := range vv {
  115. req.Header.Add(k, v)
  116. }
  117. }
  118. }
  119. }
  120. if ctx != nil {
  121. req = req.WithContext(ctx)
  122. }
  123. res, err := transport.Perform(req)
  124. if err != nil {
  125. return nil, err
  126. }
  127. response := Response{
  128. StatusCode: res.StatusCode,
  129. Body: res.Body,
  130. Header: res.Header,
  131. }
  132. return &response, nil
  133. }
  134. // WithContext sets the request context.
  135. func (f IndicesFlush) WithContext(v context.Context) func(*IndicesFlushRequest) {
  136. return func(r *IndicesFlushRequest) {
  137. r.ctx = v
  138. }
  139. }
  140. // WithIndex - a list of index names; use _all for all indices.
  141. func (f IndicesFlush) WithIndex(v ...string) func(*IndicesFlushRequest) {
  142. return func(r *IndicesFlushRequest) {
  143. r.Index = v
  144. }
  145. }
  146. // 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).
  147. func (f IndicesFlush) WithAllowNoIndices(v bool) func(*IndicesFlushRequest) {
  148. return func(r *IndicesFlushRequest) {
  149. r.AllowNoIndices = &v
  150. }
  151. }
  152. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  153. func (f IndicesFlush) WithExpandWildcards(v string) func(*IndicesFlushRequest) {
  154. return func(r *IndicesFlushRequest) {
  155. r.ExpandWildcards = v
  156. }
  157. }
  158. // WithForce - whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. this is useful if transaction log ids should be incremented even if no uncommitted changes are present. (this setting can be considered as internal).
  159. func (f IndicesFlush) WithForce(v bool) func(*IndicesFlushRequest) {
  160. return func(r *IndicesFlushRequest) {
  161. r.Force = &v
  162. }
  163. }
  164. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  165. func (f IndicesFlush) WithIgnoreUnavailable(v bool) func(*IndicesFlushRequest) {
  166. return func(r *IndicesFlushRequest) {
  167. r.IgnoreUnavailable = &v
  168. }
  169. }
  170. // WithWaitIfOngoing - if set to true the flush operation will block until the flush can be executed if another flush operation is already executing. the default is true. if set to false the flush will be skipped iff if another flush operation is already running..
  171. func (f IndicesFlush) WithWaitIfOngoing(v bool) func(*IndicesFlushRequest) {
  172. return func(r *IndicesFlushRequest) {
  173. r.WaitIfOngoing = &v
  174. }
  175. }
  176. // WithPretty makes the response body pretty-printed.
  177. func (f IndicesFlush) WithPretty() func(*IndicesFlushRequest) {
  178. return func(r *IndicesFlushRequest) {
  179. r.Pretty = true
  180. }
  181. }
  182. // WithHuman makes statistical values human-readable.
  183. func (f IndicesFlush) WithHuman() func(*IndicesFlushRequest) {
  184. return func(r *IndicesFlushRequest) {
  185. r.Human = true
  186. }
  187. }
  188. // WithErrorTrace includes the stack trace for errors in the response body.
  189. func (f IndicesFlush) WithErrorTrace() func(*IndicesFlushRequest) {
  190. return func(r *IndicesFlushRequest) {
  191. r.ErrorTrace = true
  192. }
  193. }
  194. // WithFilterPath filters the properties of the response body.
  195. func (f IndicesFlush) WithFilterPath(v ...string) func(*IndicesFlushRequest) {
  196. return func(r *IndicesFlushRequest) {
  197. r.FilterPath = v
  198. }
  199. }
  200. // WithHeader adds the headers to the HTTP request.
  201. func (f IndicesFlush) WithHeader(h map[string]string) func(*IndicesFlushRequest) {
  202. return func(r *IndicesFlushRequest) {
  203. if r.Header == nil {
  204. r.Header = make(http.Header)
  205. }
  206. for k, v := range h {
  207. r.Header.Add(k, v)
  208. }
  209. }
  210. }
  211. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  212. func (f IndicesFlush) WithOpaqueID(s string) func(*IndicesFlushRequest) {
  213. return func(r *IndicesFlushRequest) {
  214. if r.Header == nil {
  215. r.Header = make(http.Header)
  216. }
  217. r.Header.Set("X-Opaque-Id", s)
  218. }
  219. }