api.cat.fielddata.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 newCatFielddataFunc(t Transport) CatFielddata {
  27. return func(o ...func(*CatFielddataRequest)) (*Response, error) {
  28. var r = CatFielddataRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // CatFielddata shows how much heap memory is currently being used by fielddata on every data node in the cluster.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html.
  39. type CatFielddata func(o ...func(*CatFielddataRequest)) (*Response, error)
  40. // CatFielddataRequest configures the Cat Fielddata API request.
  41. type CatFielddataRequest struct {
  42. Fields []string
  43. Bytes string
  44. Format string
  45. H []string
  46. Help *bool
  47. S []string
  48. V *bool
  49. Pretty bool
  50. Human bool
  51. ErrorTrace bool
  52. FilterPath []string
  53. Header http.Header
  54. ctx context.Context
  55. }
  56. // Do executes the request and returns response or error.
  57. func (r CatFielddataRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  58. var (
  59. method string
  60. path strings.Builder
  61. params map[string]string
  62. )
  63. method = "GET"
  64. path.Grow(1 + len("_cat") + 1 + len("fielddata") + 1 + len(strings.Join(r.Fields, ",")))
  65. path.WriteString("/")
  66. path.WriteString("_cat")
  67. path.WriteString("/")
  68. path.WriteString("fielddata")
  69. if len(r.Fields) > 0 {
  70. path.WriteString("/")
  71. path.WriteString(strings.Join(r.Fields, ","))
  72. }
  73. params = make(map[string]string)
  74. if r.Bytes != "" {
  75. params["bytes"] = r.Bytes
  76. }
  77. if len(r.Fields) > 0 {
  78. params["fields"] = strings.Join(r.Fields, ",")
  79. }
  80. if r.Format != "" {
  81. params["format"] = r.Format
  82. }
  83. if len(r.H) > 0 {
  84. params["h"] = strings.Join(r.H, ",")
  85. }
  86. if r.Help != nil {
  87. params["help"] = strconv.FormatBool(*r.Help)
  88. }
  89. if len(r.S) > 0 {
  90. params["s"] = strings.Join(r.S, ",")
  91. }
  92. if r.V != nil {
  93. params["v"] = strconv.FormatBool(*r.V)
  94. }
  95. if r.Pretty {
  96. params["pretty"] = "true"
  97. }
  98. if r.Human {
  99. params["human"] = "true"
  100. }
  101. if r.ErrorTrace {
  102. params["error_trace"] = "true"
  103. }
  104. if len(r.FilterPath) > 0 {
  105. params["filter_path"] = strings.Join(r.FilterPath, ",")
  106. }
  107. req, err := newRequest(method, path.String(), nil)
  108. if err != nil {
  109. return nil, err
  110. }
  111. if len(params) > 0 {
  112. q := req.URL.Query()
  113. for k, v := range params {
  114. q.Set(k, v)
  115. }
  116. req.URL.RawQuery = q.Encode()
  117. }
  118. if len(r.Header) > 0 {
  119. if len(req.Header) == 0 {
  120. req.Header = r.Header
  121. } else {
  122. for k, vv := range r.Header {
  123. for _, v := range vv {
  124. req.Header.Add(k, v)
  125. }
  126. }
  127. }
  128. }
  129. if ctx != nil {
  130. req = req.WithContext(ctx)
  131. }
  132. res, err := transport.Perform(req)
  133. if err != nil {
  134. return nil, err
  135. }
  136. response := Response{
  137. StatusCode: res.StatusCode,
  138. Body: res.Body,
  139. Header: res.Header,
  140. }
  141. return &response, nil
  142. }
  143. // WithContext sets the request context.
  144. func (f CatFielddata) WithContext(v context.Context) func(*CatFielddataRequest) {
  145. return func(r *CatFielddataRequest) {
  146. r.ctx = v
  147. }
  148. }
  149. // WithFields - a list of fields to return the fielddata size.
  150. func (f CatFielddata) WithFields(v ...string) func(*CatFielddataRequest) {
  151. return func(r *CatFielddataRequest) {
  152. r.Fields = v
  153. }
  154. }
  155. // WithBytes - the unit in which to display byte values.
  156. func (f CatFielddata) WithBytes(v string) func(*CatFielddataRequest) {
  157. return func(r *CatFielddataRequest) {
  158. r.Bytes = v
  159. }
  160. }
  161. // WithFormat - a short version of the accept header, e.g. json, yaml.
  162. func (f CatFielddata) WithFormat(v string) func(*CatFielddataRequest) {
  163. return func(r *CatFielddataRequest) {
  164. r.Format = v
  165. }
  166. }
  167. // WithH - comma-separated list of column names to display.
  168. func (f CatFielddata) WithH(v ...string) func(*CatFielddataRequest) {
  169. return func(r *CatFielddataRequest) {
  170. r.H = v
  171. }
  172. }
  173. // WithHelp - return help information.
  174. func (f CatFielddata) WithHelp(v bool) func(*CatFielddataRequest) {
  175. return func(r *CatFielddataRequest) {
  176. r.Help = &v
  177. }
  178. }
  179. // WithS - comma-separated list of column names or column aliases to sort by.
  180. func (f CatFielddata) WithS(v ...string) func(*CatFielddataRequest) {
  181. return func(r *CatFielddataRequest) {
  182. r.S = v
  183. }
  184. }
  185. // WithV - verbose mode. display column headers.
  186. func (f CatFielddata) WithV(v bool) func(*CatFielddataRequest) {
  187. return func(r *CatFielddataRequest) {
  188. r.V = &v
  189. }
  190. }
  191. // WithPretty makes the response body pretty-printed.
  192. func (f CatFielddata) WithPretty() func(*CatFielddataRequest) {
  193. return func(r *CatFielddataRequest) {
  194. r.Pretty = true
  195. }
  196. }
  197. // WithHuman makes statistical values human-readable.
  198. func (f CatFielddata) WithHuman() func(*CatFielddataRequest) {
  199. return func(r *CatFielddataRequest) {
  200. r.Human = true
  201. }
  202. }
  203. // WithErrorTrace includes the stack trace for errors in the response body.
  204. func (f CatFielddata) WithErrorTrace() func(*CatFielddataRequest) {
  205. return func(r *CatFielddataRequest) {
  206. r.ErrorTrace = true
  207. }
  208. }
  209. // WithFilterPath filters the properties of the response body.
  210. func (f CatFielddata) WithFilterPath(v ...string) func(*CatFielddataRequest) {
  211. return func(r *CatFielddataRequest) {
  212. r.FilterPath = v
  213. }
  214. }
  215. // WithHeader adds the headers to the HTTP request.
  216. func (f CatFielddata) WithHeader(h map[string]string) func(*CatFielddataRequest) {
  217. return func(r *CatFielddataRequest) {
  218. if r.Header == nil {
  219. r.Header = make(http.Header)
  220. }
  221. for k, v := range h {
  222. r.Header.Add(k, v)
  223. }
  224. }
  225. }
  226. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  227. func (f CatFielddata) WithOpaqueID(s string) func(*CatFielddataRequest) {
  228. return func(r *CatFielddataRequest) {
  229. if r.Header == nil {
  230. r.Header = make(http.Header)
  231. }
  232. r.Header.Set("X-Opaque-Id", s)
  233. }
  234. }