api.cat.indices.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 newCatIndicesFunc(t Transport) CatIndices {
  28. return func(o ...func(*CatIndicesRequest)) (*Response, error) {
  29. var r = CatIndicesRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // CatIndices returns information about indices: number of primaries and replicas, document counts, disk size, ...
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html.
  40. type CatIndices func(o ...func(*CatIndicesRequest)) (*Response, error)
  41. // CatIndicesRequest configures the Cat Indices API request.
  42. type CatIndicesRequest struct {
  43. Index []string
  44. Bytes string
  45. ExpandWildcards string
  46. Format string
  47. H []string
  48. Health string
  49. Help *bool
  50. IncludeUnloadedSegments *bool
  51. Local *bool
  52. MasterTimeout time.Duration
  53. Pri *bool
  54. S []string
  55. Time string
  56. V *bool
  57. Pretty bool
  58. Human bool
  59. ErrorTrace bool
  60. FilterPath []string
  61. Header http.Header
  62. ctx context.Context
  63. }
  64. // Do executes the request and returns response or error.
  65. func (r CatIndicesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  66. var (
  67. method string
  68. path strings.Builder
  69. params map[string]string
  70. )
  71. method = "GET"
  72. path.Grow(1 + len("_cat") + 1 + len("indices") + 1 + len(strings.Join(r.Index, ",")))
  73. path.WriteString("/")
  74. path.WriteString("_cat")
  75. path.WriteString("/")
  76. path.WriteString("indices")
  77. if len(r.Index) > 0 {
  78. path.WriteString("/")
  79. path.WriteString(strings.Join(r.Index, ","))
  80. }
  81. params = make(map[string]string)
  82. if r.Bytes != "" {
  83. params["bytes"] = r.Bytes
  84. }
  85. if r.ExpandWildcards != "" {
  86. params["expand_wildcards"] = r.ExpandWildcards
  87. }
  88. if r.Format != "" {
  89. params["format"] = r.Format
  90. }
  91. if len(r.H) > 0 {
  92. params["h"] = strings.Join(r.H, ",")
  93. }
  94. if r.Health != "" {
  95. params["health"] = r.Health
  96. }
  97. if r.Help != nil {
  98. params["help"] = strconv.FormatBool(*r.Help)
  99. }
  100. if r.IncludeUnloadedSegments != nil {
  101. params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments)
  102. }
  103. if r.Local != nil {
  104. params["local"] = strconv.FormatBool(*r.Local)
  105. }
  106. if r.MasterTimeout != 0 {
  107. params["master_timeout"] = formatDuration(r.MasterTimeout)
  108. }
  109. if r.Pri != nil {
  110. params["pri"] = strconv.FormatBool(*r.Pri)
  111. }
  112. if len(r.S) > 0 {
  113. params["s"] = strings.Join(r.S, ",")
  114. }
  115. if r.Time != "" {
  116. params["time"] = r.Time
  117. }
  118. if r.V != nil {
  119. params["v"] = strconv.FormatBool(*r.V)
  120. }
  121. if r.Pretty {
  122. params["pretty"] = "true"
  123. }
  124. if r.Human {
  125. params["human"] = "true"
  126. }
  127. if r.ErrorTrace {
  128. params["error_trace"] = "true"
  129. }
  130. if len(r.FilterPath) > 0 {
  131. params["filter_path"] = strings.Join(r.FilterPath, ",")
  132. }
  133. req, err := newRequest(method, path.String(), nil)
  134. if err != nil {
  135. return nil, err
  136. }
  137. if len(params) > 0 {
  138. q := req.URL.Query()
  139. for k, v := range params {
  140. q.Set(k, v)
  141. }
  142. req.URL.RawQuery = q.Encode()
  143. }
  144. if len(r.Header) > 0 {
  145. if len(req.Header) == 0 {
  146. req.Header = r.Header
  147. } else {
  148. for k, vv := range r.Header {
  149. for _, v := range vv {
  150. req.Header.Add(k, v)
  151. }
  152. }
  153. }
  154. }
  155. if ctx != nil {
  156. req = req.WithContext(ctx)
  157. }
  158. res, err := transport.Perform(req)
  159. if err != nil {
  160. return nil, err
  161. }
  162. response := Response{
  163. StatusCode: res.StatusCode,
  164. Body: res.Body,
  165. Header: res.Header,
  166. }
  167. return &response, nil
  168. }
  169. // WithContext sets the request context.
  170. func (f CatIndices) WithContext(v context.Context) func(*CatIndicesRequest) {
  171. return func(r *CatIndicesRequest) {
  172. r.ctx = v
  173. }
  174. }
  175. // WithIndex - a list of index names to limit the returned information.
  176. func (f CatIndices) WithIndex(v ...string) func(*CatIndicesRequest) {
  177. return func(r *CatIndicesRequest) {
  178. r.Index = v
  179. }
  180. }
  181. // WithBytes - the unit in which to display byte values.
  182. func (f CatIndices) WithBytes(v string) func(*CatIndicesRequest) {
  183. return func(r *CatIndicesRequest) {
  184. r.Bytes = v
  185. }
  186. }
  187. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  188. func (f CatIndices) WithExpandWildcards(v string) func(*CatIndicesRequest) {
  189. return func(r *CatIndicesRequest) {
  190. r.ExpandWildcards = v
  191. }
  192. }
  193. // WithFormat - a short version of the accept header, e.g. json, yaml.
  194. func (f CatIndices) WithFormat(v string) func(*CatIndicesRequest) {
  195. return func(r *CatIndicesRequest) {
  196. r.Format = v
  197. }
  198. }
  199. // WithH - comma-separated list of column names to display.
  200. func (f CatIndices) WithH(v ...string) func(*CatIndicesRequest) {
  201. return func(r *CatIndicesRequest) {
  202. r.H = v
  203. }
  204. }
  205. // WithHealth - a health status ("green", "yellow", or "red" to filter only indices matching the specified health status.
  206. func (f CatIndices) WithHealth(v string) func(*CatIndicesRequest) {
  207. return func(r *CatIndicesRequest) {
  208. r.Health = v
  209. }
  210. }
  211. // WithHelp - return help information.
  212. func (f CatIndices) WithHelp(v bool) func(*CatIndicesRequest) {
  213. return func(r *CatIndicesRequest) {
  214. r.Help = &v
  215. }
  216. }
  217. // WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory.
  218. func (f CatIndices) WithIncludeUnloadedSegments(v bool) func(*CatIndicesRequest) {
  219. return func(r *CatIndicesRequest) {
  220. r.IncludeUnloadedSegments = &v
  221. }
  222. }
  223. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  224. func (f CatIndices) WithLocal(v bool) func(*CatIndicesRequest) {
  225. return func(r *CatIndicesRequest) {
  226. r.Local = &v
  227. }
  228. }
  229. // WithMasterTimeout - explicit operation timeout for connection to master node.
  230. func (f CatIndices) WithMasterTimeout(v time.Duration) func(*CatIndicesRequest) {
  231. return func(r *CatIndicesRequest) {
  232. r.MasterTimeout = v
  233. }
  234. }
  235. // WithPri - set to true to return stats only for primary shards.
  236. func (f CatIndices) WithPri(v bool) func(*CatIndicesRequest) {
  237. return func(r *CatIndicesRequest) {
  238. r.Pri = &v
  239. }
  240. }
  241. // WithS - comma-separated list of column names or column aliases to sort by.
  242. func (f CatIndices) WithS(v ...string) func(*CatIndicesRequest) {
  243. return func(r *CatIndicesRequest) {
  244. r.S = v
  245. }
  246. }
  247. // WithTime - the unit in which to display time values.
  248. func (f CatIndices) WithTime(v string) func(*CatIndicesRequest) {
  249. return func(r *CatIndicesRequest) {
  250. r.Time = v
  251. }
  252. }
  253. // WithV - verbose mode. display column headers.
  254. func (f CatIndices) WithV(v bool) func(*CatIndicesRequest) {
  255. return func(r *CatIndicesRequest) {
  256. r.V = &v
  257. }
  258. }
  259. // WithPretty makes the response body pretty-printed.
  260. func (f CatIndices) WithPretty() func(*CatIndicesRequest) {
  261. return func(r *CatIndicesRequest) {
  262. r.Pretty = true
  263. }
  264. }
  265. // WithHuman makes statistical values human-readable.
  266. func (f CatIndices) WithHuman() func(*CatIndicesRequest) {
  267. return func(r *CatIndicesRequest) {
  268. r.Human = true
  269. }
  270. }
  271. // WithErrorTrace includes the stack trace for errors in the response body.
  272. func (f CatIndices) WithErrorTrace() func(*CatIndicesRequest) {
  273. return func(r *CatIndicesRequest) {
  274. r.ErrorTrace = true
  275. }
  276. }
  277. // WithFilterPath filters the properties of the response body.
  278. func (f CatIndices) WithFilterPath(v ...string) func(*CatIndicesRequest) {
  279. return func(r *CatIndicesRequest) {
  280. r.FilterPath = v
  281. }
  282. }
  283. // WithHeader adds the headers to the HTTP request.
  284. func (f CatIndices) WithHeader(h map[string]string) func(*CatIndicesRequest) {
  285. return func(r *CatIndicesRequest) {
  286. if r.Header == nil {
  287. r.Header = make(http.Header)
  288. }
  289. for k, v := range h {
  290. r.Header.Add(k, v)
  291. }
  292. }
  293. }
  294. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  295. func (f CatIndices) WithOpaqueID(s string) func(*CatIndicesRequest) {
  296. return func(r *CatIndicesRequest) {
  297. if r.Header == nil {
  298. r.Header = make(http.Header)
  299. }
  300. r.Header.Set("X-Opaque-Id", s)
  301. }
  302. }