api.indices.stats.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 newIndicesStatsFunc(t Transport) IndicesStats {
  27. return func(o ...func(*IndicesStatsRequest)) (*Response, error) {
  28. var r = IndicesStatsRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // IndicesStats provides statistics on operations happening in an index.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html.
  39. type IndicesStats func(o ...func(*IndicesStatsRequest)) (*Response, error)
  40. // IndicesStatsRequest configures the Indices Stats API request.
  41. type IndicesStatsRequest struct {
  42. Index []string
  43. Metric []string
  44. CompletionFields []string
  45. ExpandWildcards string
  46. FielddataFields []string
  47. Fields []string
  48. ForbidClosedIndices *bool
  49. Groups []string
  50. IncludeSegmentFileSizes *bool
  51. IncludeUnloadedSegments *bool
  52. Level string
  53. Types []string
  54. Pretty bool
  55. Human bool
  56. ErrorTrace bool
  57. FilterPath []string
  58. Header http.Header
  59. ctx context.Context
  60. }
  61. // Do executes the request and returns response or error.
  62. func (r IndicesStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  63. var (
  64. method string
  65. path strings.Builder
  66. params map[string]string
  67. )
  68. method = "GET"
  69. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_stats") + 1 + len(strings.Join(r.Metric, ",")))
  70. if len(r.Index) > 0 {
  71. path.WriteString("/")
  72. path.WriteString(strings.Join(r.Index, ","))
  73. }
  74. path.WriteString("/")
  75. path.WriteString("_stats")
  76. if len(r.Metric) > 0 {
  77. path.WriteString("/")
  78. path.WriteString(strings.Join(r.Metric, ","))
  79. }
  80. params = make(map[string]string)
  81. if len(r.CompletionFields) > 0 {
  82. params["completion_fields"] = strings.Join(r.CompletionFields, ",")
  83. }
  84. if r.ExpandWildcards != "" {
  85. params["expand_wildcards"] = r.ExpandWildcards
  86. }
  87. if len(r.FielddataFields) > 0 {
  88. params["fielddata_fields"] = strings.Join(r.FielddataFields, ",")
  89. }
  90. if len(r.Fields) > 0 {
  91. params["fields"] = strings.Join(r.Fields, ",")
  92. }
  93. if r.ForbidClosedIndices != nil {
  94. params["forbid_closed_indices"] = strconv.FormatBool(*r.ForbidClosedIndices)
  95. }
  96. if len(r.Groups) > 0 {
  97. params["groups"] = strings.Join(r.Groups, ",")
  98. }
  99. if r.IncludeSegmentFileSizes != nil {
  100. params["include_segment_file_sizes"] = strconv.FormatBool(*r.IncludeSegmentFileSizes)
  101. }
  102. if r.IncludeUnloadedSegments != nil {
  103. params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments)
  104. }
  105. if r.Level != "" {
  106. params["level"] = r.Level
  107. }
  108. if len(r.Types) > 0 {
  109. params["types"] = strings.Join(r.Types, ",")
  110. }
  111. if r.Pretty {
  112. params["pretty"] = "true"
  113. }
  114. if r.Human {
  115. params["human"] = "true"
  116. }
  117. if r.ErrorTrace {
  118. params["error_trace"] = "true"
  119. }
  120. if len(r.FilterPath) > 0 {
  121. params["filter_path"] = strings.Join(r.FilterPath, ",")
  122. }
  123. req, err := newRequest(method, path.String(), nil)
  124. if err != nil {
  125. return nil, err
  126. }
  127. if len(params) > 0 {
  128. q := req.URL.Query()
  129. for k, v := range params {
  130. q.Set(k, v)
  131. }
  132. req.URL.RawQuery = q.Encode()
  133. }
  134. if len(r.Header) > 0 {
  135. if len(req.Header) == 0 {
  136. req.Header = r.Header
  137. } else {
  138. for k, vv := range r.Header {
  139. for _, v := range vv {
  140. req.Header.Add(k, v)
  141. }
  142. }
  143. }
  144. }
  145. if ctx != nil {
  146. req = req.WithContext(ctx)
  147. }
  148. res, err := transport.Perform(req)
  149. if err != nil {
  150. return nil, err
  151. }
  152. response := Response{
  153. StatusCode: res.StatusCode,
  154. Body: res.Body,
  155. Header: res.Header,
  156. }
  157. return &response, nil
  158. }
  159. // WithContext sets the request context.
  160. func (f IndicesStats) WithContext(v context.Context) func(*IndicesStatsRequest) {
  161. return func(r *IndicesStatsRequest) {
  162. r.ctx = v
  163. }
  164. }
  165. // WithIndex - a list of index names; use _all to perform the operation on all indices.
  166. func (f IndicesStats) WithIndex(v ...string) func(*IndicesStatsRequest) {
  167. return func(r *IndicesStatsRequest) {
  168. r.Index = v
  169. }
  170. }
  171. // WithMetric - limit the information returned the specific metrics..
  172. func (f IndicesStats) WithMetric(v ...string) func(*IndicesStatsRequest) {
  173. return func(r *IndicesStatsRequest) {
  174. r.Metric = v
  175. }
  176. }
  177. // WithCompletionFields - a list of fields for `fielddata` and `suggest` index metric (supports wildcards).
  178. func (f IndicesStats) WithCompletionFields(v ...string) func(*IndicesStatsRequest) {
  179. return func(r *IndicesStatsRequest) {
  180. r.CompletionFields = v
  181. }
  182. }
  183. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  184. func (f IndicesStats) WithExpandWildcards(v string) func(*IndicesStatsRequest) {
  185. return func(r *IndicesStatsRequest) {
  186. r.ExpandWildcards = v
  187. }
  188. }
  189. // WithFielddataFields - a list of fields for `fielddata` index metric (supports wildcards).
  190. func (f IndicesStats) WithFielddataFields(v ...string) func(*IndicesStatsRequest) {
  191. return func(r *IndicesStatsRequest) {
  192. r.FielddataFields = v
  193. }
  194. }
  195. // WithFields - a list of fields for `fielddata` and `completion` index metric (supports wildcards).
  196. func (f IndicesStats) WithFields(v ...string) func(*IndicesStatsRequest) {
  197. return func(r *IndicesStatsRequest) {
  198. r.Fields = v
  199. }
  200. }
  201. // WithForbidClosedIndices - if set to false stats will also collected from closed indices if explicitly specified or if expand_wildcards expands to closed indices.
  202. func (f IndicesStats) WithForbidClosedIndices(v bool) func(*IndicesStatsRequest) {
  203. return func(r *IndicesStatsRequest) {
  204. r.ForbidClosedIndices = &v
  205. }
  206. }
  207. // WithGroups - a list of search groups for `search` index metric.
  208. func (f IndicesStats) WithGroups(v ...string) func(*IndicesStatsRequest) {
  209. return func(r *IndicesStatsRequest) {
  210. r.Groups = v
  211. }
  212. }
  213. // WithIncludeSegmentFileSizes - whether to report the aggregated disk usage of each one of the lucene index files (only applies if segment stats are requested).
  214. func (f IndicesStats) WithIncludeSegmentFileSizes(v bool) func(*IndicesStatsRequest) {
  215. return func(r *IndicesStatsRequest) {
  216. r.IncludeSegmentFileSizes = &v
  217. }
  218. }
  219. // WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory.
  220. func (f IndicesStats) WithIncludeUnloadedSegments(v bool) func(*IndicesStatsRequest) {
  221. return func(r *IndicesStatsRequest) {
  222. r.IncludeUnloadedSegments = &v
  223. }
  224. }
  225. // WithLevel - return stats aggregated at cluster, index or shard level.
  226. func (f IndicesStats) WithLevel(v string) func(*IndicesStatsRequest) {
  227. return func(r *IndicesStatsRequest) {
  228. r.Level = v
  229. }
  230. }
  231. // WithTypes - a list of document types for the `indexing` index metric.
  232. func (f IndicesStats) WithTypes(v ...string) func(*IndicesStatsRequest) {
  233. return func(r *IndicesStatsRequest) {
  234. r.Types = v
  235. }
  236. }
  237. // WithPretty makes the response body pretty-printed.
  238. func (f IndicesStats) WithPretty() func(*IndicesStatsRequest) {
  239. return func(r *IndicesStatsRequest) {
  240. r.Pretty = true
  241. }
  242. }
  243. // WithHuman makes statistical values human-readable.
  244. func (f IndicesStats) WithHuman() func(*IndicesStatsRequest) {
  245. return func(r *IndicesStatsRequest) {
  246. r.Human = true
  247. }
  248. }
  249. // WithErrorTrace includes the stack trace for errors in the response body.
  250. func (f IndicesStats) WithErrorTrace() func(*IndicesStatsRequest) {
  251. return func(r *IndicesStatsRequest) {
  252. r.ErrorTrace = true
  253. }
  254. }
  255. // WithFilterPath filters the properties of the response body.
  256. func (f IndicesStats) WithFilterPath(v ...string) func(*IndicesStatsRequest) {
  257. return func(r *IndicesStatsRequest) {
  258. r.FilterPath = v
  259. }
  260. }
  261. // WithHeader adds the headers to the HTTP request.
  262. func (f IndicesStats) WithHeader(h map[string]string) func(*IndicesStatsRequest) {
  263. return func(r *IndicesStatsRequest) {
  264. if r.Header == nil {
  265. r.Header = make(http.Header)
  266. }
  267. for k, v := range h {
  268. r.Header.Add(k, v)
  269. }
  270. }
  271. }
  272. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  273. func (f IndicesStats) WithOpaqueID(s string) func(*IndicesStatsRequest) {
  274. return func(r *IndicesStatsRequest) {
  275. if r.Header == nil {
  276. r.Header = make(http.Header)
  277. }
  278. r.Header.Set("X-Opaque-Id", s)
  279. }
  280. }