api.xpack.enrich.stats.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. "strings"
  24. )
  25. func newEnrichStatsFunc(t Transport) EnrichStats {
  26. return func(o ...func(*EnrichStatsRequest)) (*Response, error) {
  27. var r = EnrichStatsRequest{}
  28. for _, f := range o {
  29. f(&r)
  30. }
  31. return r.Do(r.ctx, t)
  32. }
  33. }
  34. // ----- API Definition -------------------------------------------------------
  35. // EnrichStats - Gets enrich coordinator statistics and information about enrich policies that are currently executing.
  36. //
  37. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-stats-api.html.
  38. type EnrichStats func(o ...func(*EnrichStatsRequest)) (*Response, error)
  39. // EnrichStatsRequest configures the Enrich Stats API request.
  40. type EnrichStatsRequest struct {
  41. Pretty bool
  42. Human bool
  43. ErrorTrace bool
  44. FilterPath []string
  45. Header http.Header
  46. ctx context.Context
  47. }
  48. // Do executes the request and returns response or error.
  49. func (r EnrichStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  50. var (
  51. method string
  52. path strings.Builder
  53. params map[string]string
  54. )
  55. method = "GET"
  56. path.Grow(len("/_enrich/_stats"))
  57. path.WriteString("/_enrich/_stats")
  58. params = make(map[string]string)
  59. if r.Pretty {
  60. params["pretty"] = "true"
  61. }
  62. if r.Human {
  63. params["human"] = "true"
  64. }
  65. if r.ErrorTrace {
  66. params["error_trace"] = "true"
  67. }
  68. if len(r.FilterPath) > 0 {
  69. params["filter_path"] = strings.Join(r.FilterPath, ",")
  70. }
  71. req, err := newRequest(method, path.String(), nil)
  72. if err != nil {
  73. return nil, err
  74. }
  75. if len(params) > 0 {
  76. q := req.URL.Query()
  77. for k, v := range params {
  78. q.Set(k, v)
  79. }
  80. req.URL.RawQuery = q.Encode()
  81. }
  82. if len(r.Header) > 0 {
  83. if len(req.Header) == 0 {
  84. req.Header = r.Header
  85. } else {
  86. for k, vv := range r.Header {
  87. for _, v := range vv {
  88. req.Header.Add(k, v)
  89. }
  90. }
  91. }
  92. }
  93. if ctx != nil {
  94. req = req.WithContext(ctx)
  95. }
  96. res, err := transport.Perform(req)
  97. if err != nil {
  98. return nil, err
  99. }
  100. response := Response{
  101. StatusCode: res.StatusCode,
  102. Body: res.Body,
  103. Header: res.Header,
  104. }
  105. return &response, nil
  106. }
  107. // WithContext sets the request context.
  108. func (f EnrichStats) WithContext(v context.Context) func(*EnrichStatsRequest) {
  109. return func(r *EnrichStatsRequest) {
  110. r.ctx = v
  111. }
  112. }
  113. // WithPretty makes the response body pretty-printed.
  114. func (f EnrichStats) WithPretty() func(*EnrichStatsRequest) {
  115. return func(r *EnrichStatsRequest) {
  116. r.Pretty = true
  117. }
  118. }
  119. // WithHuman makes statistical values human-readable.
  120. func (f EnrichStats) WithHuman() func(*EnrichStatsRequest) {
  121. return func(r *EnrichStatsRequest) {
  122. r.Human = true
  123. }
  124. }
  125. // WithErrorTrace includes the stack trace for errors in the response body.
  126. func (f EnrichStats) WithErrorTrace() func(*EnrichStatsRequest) {
  127. return func(r *EnrichStatsRequest) {
  128. r.ErrorTrace = true
  129. }
  130. }
  131. // WithFilterPath filters the properties of the response body.
  132. func (f EnrichStats) WithFilterPath(v ...string) func(*EnrichStatsRequest) {
  133. return func(r *EnrichStatsRequest) {
  134. r.FilterPath = v
  135. }
  136. }
  137. // WithHeader adds the headers to the HTTP request.
  138. func (f EnrichStats) WithHeader(h map[string]string) func(*EnrichStatsRequest) {
  139. return func(r *EnrichStatsRequest) {
  140. if r.Header == nil {
  141. r.Header = make(http.Header)
  142. }
  143. for k, v := range h {
  144. r.Header.Add(k, v)
  145. }
  146. }
  147. }
  148. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  149. func (f EnrichStats) WithOpaqueID(s string) func(*EnrichStatsRequest) {
  150. return func(r *EnrichStatsRequest) {
  151. if r.Header == nil {
  152. r.Header = make(http.Header)
  153. }
  154. r.Header.Set("X-Opaque-Id", s)
  155. }
  156. }