api.indices.segments.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 newIndicesSegmentsFunc(t Transport) IndicesSegments {
  27. return func(o ...func(*IndicesSegmentsRequest)) (*Response, error) {
  28. var r = IndicesSegmentsRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // IndicesSegments provides low-level information about segments in a Lucene index.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html.
  39. type IndicesSegments func(o ...func(*IndicesSegmentsRequest)) (*Response, error)
  40. // IndicesSegmentsRequest configures the Indices Segments API request.
  41. type IndicesSegmentsRequest struct {
  42. Index []string
  43. AllowNoIndices *bool
  44. ExpandWildcards string
  45. IgnoreUnavailable *bool
  46. Verbose *bool
  47. Pretty bool
  48. Human bool
  49. ErrorTrace bool
  50. FilterPath []string
  51. Header http.Header
  52. ctx context.Context
  53. }
  54. // Do executes the request and returns response or error.
  55. func (r IndicesSegmentsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  56. var (
  57. method string
  58. path strings.Builder
  59. params map[string]string
  60. )
  61. method = "GET"
  62. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_segments"))
  63. if len(r.Index) > 0 {
  64. path.WriteString("/")
  65. path.WriteString(strings.Join(r.Index, ","))
  66. }
  67. path.WriteString("/")
  68. path.WriteString("_segments")
  69. params = make(map[string]string)
  70. if r.AllowNoIndices != nil {
  71. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  72. }
  73. if r.ExpandWildcards != "" {
  74. params["expand_wildcards"] = r.ExpandWildcards
  75. }
  76. if r.IgnoreUnavailable != nil {
  77. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  78. }
  79. if r.Verbose != nil {
  80. params["verbose"] = strconv.FormatBool(*r.Verbose)
  81. }
  82. if r.Pretty {
  83. params["pretty"] = "true"
  84. }
  85. if r.Human {
  86. params["human"] = "true"
  87. }
  88. if r.ErrorTrace {
  89. params["error_trace"] = "true"
  90. }
  91. if len(r.FilterPath) > 0 {
  92. params["filter_path"] = strings.Join(r.FilterPath, ",")
  93. }
  94. req, err := newRequest(method, path.String(), nil)
  95. if err != nil {
  96. return nil, err
  97. }
  98. if len(params) > 0 {
  99. q := req.URL.Query()
  100. for k, v := range params {
  101. q.Set(k, v)
  102. }
  103. req.URL.RawQuery = q.Encode()
  104. }
  105. if len(r.Header) > 0 {
  106. if len(req.Header) == 0 {
  107. req.Header = r.Header
  108. } else {
  109. for k, vv := range r.Header {
  110. for _, v := range vv {
  111. req.Header.Add(k, v)
  112. }
  113. }
  114. }
  115. }
  116. if ctx != nil {
  117. req = req.WithContext(ctx)
  118. }
  119. res, err := transport.Perform(req)
  120. if err != nil {
  121. return nil, err
  122. }
  123. response := Response{
  124. StatusCode: res.StatusCode,
  125. Body: res.Body,
  126. Header: res.Header,
  127. }
  128. return &response, nil
  129. }
  130. // WithContext sets the request context.
  131. func (f IndicesSegments) WithContext(v context.Context) func(*IndicesSegmentsRequest) {
  132. return func(r *IndicesSegmentsRequest) {
  133. r.ctx = v
  134. }
  135. }
  136. // WithIndex - a list of index names; use _all to perform the operation on all indices.
  137. func (f IndicesSegments) WithIndex(v ...string) func(*IndicesSegmentsRequest) {
  138. return func(r *IndicesSegmentsRequest) {
  139. r.Index = v
  140. }
  141. }
  142. // 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).
  143. func (f IndicesSegments) WithAllowNoIndices(v bool) func(*IndicesSegmentsRequest) {
  144. return func(r *IndicesSegmentsRequest) {
  145. r.AllowNoIndices = &v
  146. }
  147. }
  148. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  149. func (f IndicesSegments) WithExpandWildcards(v string) func(*IndicesSegmentsRequest) {
  150. return func(r *IndicesSegmentsRequest) {
  151. r.ExpandWildcards = v
  152. }
  153. }
  154. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  155. func (f IndicesSegments) WithIgnoreUnavailable(v bool) func(*IndicesSegmentsRequest) {
  156. return func(r *IndicesSegmentsRequest) {
  157. r.IgnoreUnavailable = &v
  158. }
  159. }
  160. // WithVerbose - includes detailed memory usage by lucene..
  161. func (f IndicesSegments) WithVerbose(v bool) func(*IndicesSegmentsRequest) {
  162. return func(r *IndicesSegmentsRequest) {
  163. r.Verbose = &v
  164. }
  165. }
  166. // WithPretty makes the response body pretty-printed.
  167. func (f IndicesSegments) WithPretty() func(*IndicesSegmentsRequest) {
  168. return func(r *IndicesSegmentsRequest) {
  169. r.Pretty = true
  170. }
  171. }
  172. // WithHuman makes statistical values human-readable.
  173. func (f IndicesSegments) WithHuman() func(*IndicesSegmentsRequest) {
  174. return func(r *IndicesSegmentsRequest) {
  175. r.Human = true
  176. }
  177. }
  178. // WithErrorTrace includes the stack trace for errors in the response body.
  179. func (f IndicesSegments) WithErrorTrace() func(*IndicesSegmentsRequest) {
  180. return func(r *IndicesSegmentsRequest) {
  181. r.ErrorTrace = true
  182. }
  183. }
  184. // WithFilterPath filters the properties of the response body.
  185. func (f IndicesSegments) WithFilterPath(v ...string) func(*IndicesSegmentsRequest) {
  186. return func(r *IndicesSegmentsRequest) {
  187. r.FilterPath = v
  188. }
  189. }
  190. // WithHeader adds the headers to the HTTP request.
  191. func (f IndicesSegments) WithHeader(h map[string]string) func(*IndicesSegmentsRequest) {
  192. return func(r *IndicesSegmentsRequest) {
  193. if r.Header == nil {
  194. r.Header = make(http.Header)
  195. }
  196. for k, v := range h {
  197. r.Header.Add(k, v)
  198. }
  199. }
  200. }
  201. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  202. func (f IndicesSegments) WithOpaqueID(s string) func(*IndicesSegmentsRequest) {
  203. return func(r *IndicesSegmentsRequest) {
  204. if r.Header == nil {
  205. r.Header = make(http.Header)
  206. }
  207. r.Header.Set("X-Opaque-Id", s)
  208. }
  209. }