api.indices.clear_cache.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 newIndicesClearCacheFunc(t Transport) IndicesClearCache {
  27. return func(o ...func(*IndicesClearCacheRequest)) (*Response, error) {
  28. var r = IndicesClearCacheRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // IndicesClearCache clears all or specific caches for one or more indices.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html.
  39. type IndicesClearCache func(o ...func(*IndicesClearCacheRequest)) (*Response, error)
  40. // IndicesClearCacheRequest configures the Indices Clear Cache API request.
  41. type IndicesClearCacheRequest struct {
  42. Index []string
  43. AllowNoIndices *bool
  44. ExpandWildcards string
  45. Fielddata *bool
  46. Fields []string
  47. IgnoreUnavailable *bool
  48. Query *bool
  49. Request *bool
  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 IndicesClearCacheRequest) 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(strings.Join(r.Index, ",")) + 1 + len("_cache") + 1 + len("clear"))
  66. if len(r.Index) > 0 {
  67. path.WriteString("/")
  68. path.WriteString(strings.Join(r.Index, ","))
  69. }
  70. path.WriteString("/")
  71. path.WriteString("_cache")
  72. path.WriteString("/")
  73. path.WriteString("clear")
  74. params = make(map[string]string)
  75. if r.AllowNoIndices != nil {
  76. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  77. }
  78. if r.ExpandWildcards != "" {
  79. params["expand_wildcards"] = r.ExpandWildcards
  80. }
  81. if r.Fielddata != nil {
  82. params["fielddata"] = strconv.FormatBool(*r.Fielddata)
  83. }
  84. if len(r.Fields) > 0 {
  85. params["fields"] = strings.Join(r.Fields, ",")
  86. }
  87. if r.IgnoreUnavailable != nil {
  88. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  89. }
  90. if len(r.Index) > 0 {
  91. params["index"] = strings.Join(r.Index, ",")
  92. }
  93. if r.Query != nil {
  94. params["query"] = strconv.FormatBool(*r.Query)
  95. }
  96. if r.Request != nil {
  97. params["request"] = strconv.FormatBool(*r.Request)
  98. }
  99. if r.Pretty {
  100. params["pretty"] = "true"
  101. }
  102. if r.Human {
  103. params["human"] = "true"
  104. }
  105. if r.ErrorTrace {
  106. params["error_trace"] = "true"
  107. }
  108. if len(r.FilterPath) > 0 {
  109. params["filter_path"] = strings.Join(r.FilterPath, ",")
  110. }
  111. req, err := newRequest(method, path.String(), nil)
  112. if err != nil {
  113. return nil, err
  114. }
  115. if len(params) > 0 {
  116. q := req.URL.Query()
  117. for k, v := range params {
  118. q.Set(k, v)
  119. }
  120. req.URL.RawQuery = q.Encode()
  121. }
  122. if len(r.Header) > 0 {
  123. if len(req.Header) == 0 {
  124. req.Header = r.Header
  125. } else {
  126. for k, vv := range r.Header {
  127. for _, v := range vv {
  128. req.Header.Add(k, v)
  129. }
  130. }
  131. }
  132. }
  133. if ctx != nil {
  134. req = req.WithContext(ctx)
  135. }
  136. res, err := transport.Perform(req)
  137. if err != nil {
  138. return nil, err
  139. }
  140. response := Response{
  141. StatusCode: res.StatusCode,
  142. Body: res.Body,
  143. Header: res.Header,
  144. }
  145. return &response, nil
  146. }
  147. // WithContext sets the request context.
  148. func (f IndicesClearCache) WithContext(v context.Context) func(*IndicesClearCacheRequest) {
  149. return func(r *IndicesClearCacheRequest) {
  150. r.ctx = v
  151. }
  152. }
  153. // WithIndex - a list of index name to limit the operation.
  154. func (f IndicesClearCache) WithIndex(v ...string) func(*IndicesClearCacheRequest) {
  155. return func(r *IndicesClearCacheRequest) {
  156. r.Index = v
  157. }
  158. }
  159. // 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).
  160. func (f IndicesClearCache) WithAllowNoIndices(v bool) func(*IndicesClearCacheRequest) {
  161. return func(r *IndicesClearCacheRequest) {
  162. r.AllowNoIndices = &v
  163. }
  164. }
  165. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  166. func (f IndicesClearCache) WithExpandWildcards(v string) func(*IndicesClearCacheRequest) {
  167. return func(r *IndicesClearCacheRequest) {
  168. r.ExpandWildcards = v
  169. }
  170. }
  171. // WithFielddata - clear field data.
  172. func (f IndicesClearCache) WithFielddata(v bool) func(*IndicesClearCacheRequest) {
  173. return func(r *IndicesClearCacheRequest) {
  174. r.Fielddata = &v
  175. }
  176. }
  177. // WithFields - a list of fields to clear when using the `fielddata` parameter (default: all).
  178. func (f IndicesClearCache) WithFields(v ...string) func(*IndicesClearCacheRequest) {
  179. return func(r *IndicesClearCacheRequest) {
  180. r.Fields = v
  181. }
  182. }
  183. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  184. func (f IndicesClearCache) WithIgnoreUnavailable(v bool) func(*IndicesClearCacheRequest) {
  185. return func(r *IndicesClearCacheRequest) {
  186. r.IgnoreUnavailable = &v
  187. }
  188. }
  189. // WithQuery - clear query caches.
  190. func (f IndicesClearCache) WithQuery(v bool) func(*IndicesClearCacheRequest) {
  191. return func(r *IndicesClearCacheRequest) {
  192. r.Query = &v
  193. }
  194. }
  195. // WithRequest - clear request cache.
  196. func (f IndicesClearCache) WithRequest(v bool) func(*IndicesClearCacheRequest) {
  197. return func(r *IndicesClearCacheRequest) {
  198. r.Request = &v
  199. }
  200. }
  201. // WithPretty makes the response body pretty-printed.
  202. func (f IndicesClearCache) WithPretty() func(*IndicesClearCacheRequest) {
  203. return func(r *IndicesClearCacheRequest) {
  204. r.Pretty = true
  205. }
  206. }
  207. // WithHuman makes statistical values human-readable.
  208. func (f IndicesClearCache) WithHuman() func(*IndicesClearCacheRequest) {
  209. return func(r *IndicesClearCacheRequest) {
  210. r.Human = true
  211. }
  212. }
  213. // WithErrorTrace includes the stack trace for errors in the response body.
  214. func (f IndicesClearCache) WithErrorTrace() func(*IndicesClearCacheRequest) {
  215. return func(r *IndicesClearCacheRequest) {
  216. r.ErrorTrace = true
  217. }
  218. }
  219. // WithFilterPath filters the properties of the response body.
  220. func (f IndicesClearCache) WithFilterPath(v ...string) func(*IndicesClearCacheRequest) {
  221. return func(r *IndicesClearCacheRequest) {
  222. r.FilterPath = v
  223. }
  224. }
  225. // WithHeader adds the headers to the HTTP request.
  226. func (f IndicesClearCache) WithHeader(h map[string]string) func(*IndicesClearCacheRequest) {
  227. return func(r *IndicesClearCacheRequest) {
  228. if r.Header == nil {
  229. r.Header = make(http.Header)
  230. }
  231. for k, v := range h {
  232. r.Header.Add(k, v)
  233. }
  234. }
  235. }
  236. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  237. func (f IndicesClearCache) WithOpaqueID(s string) func(*IndicesClearCacheRequest) {
  238. return func(r *IndicesClearCacheRequest) {
  239. if r.Header == nil {
  240. r.Header = make(http.Header)
  241. }
  242. r.Header.Set("X-Opaque-Id", s)
  243. }
  244. }