api.indices.get.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. "errors"
  23. "net/http"
  24. "strconv"
  25. "strings"
  26. "time"
  27. )
  28. func newIndicesGetFunc(t Transport) IndicesGet {
  29. return func(index []string, o ...func(*IndicesGetRequest)) (*Response, error) {
  30. var r = IndicesGetRequest{Index: index}
  31. for _, f := range o {
  32. f(&r)
  33. }
  34. return r.Do(r.ctx, t)
  35. }
  36. }
  37. // ----- API Definition -------------------------------------------------------
  38. // IndicesGet returns information about one or more indices.
  39. //
  40. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html.
  41. type IndicesGet func(index []string, o ...func(*IndicesGetRequest)) (*Response, error)
  42. // IndicesGetRequest configures the Indices Get API request.
  43. type IndicesGetRequest struct {
  44. Index []string
  45. AllowNoIndices *bool
  46. ExpandWildcards string
  47. FlatSettings *bool
  48. IgnoreUnavailable *bool
  49. IncludeDefaults *bool
  50. IncludeTypeName *bool
  51. Local *bool
  52. MasterTimeout time.Duration
  53. Pretty bool
  54. Human bool
  55. ErrorTrace bool
  56. FilterPath []string
  57. Header http.Header
  58. ctx context.Context
  59. }
  60. // Do executes the request and returns response or error.
  61. func (r IndicesGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  62. var (
  63. method string
  64. path strings.Builder
  65. params map[string]string
  66. )
  67. method = "GET"
  68. if len(r.Index) == 0 {
  69. return nil, errors.New("index is required and cannot be nil or empty")
  70. }
  71. path.Grow(1 + len(strings.Join(r.Index, ",")))
  72. path.WriteString("/")
  73. path.WriteString(strings.Join(r.Index, ","))
  74. params = make(map[string]string)
  75. if r.AllowNoIndices != nil {
  76. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  77. }
  78. if r.ExpandWildcards != "" {
  79. params["expand_wildcards"] = r.ExpandWildcards
  80. }
  81. if r.FlatSettings != nil {
  82. params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
  83. }
  84. if r.IgnoreUnavailable != nil {
  85. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  86. }
  87. if r.IncludeDefaults != nil {
  88. params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults)
  89. }
  90. if r.IncludeTypeName != nil {
  91. params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName)
  92. }
  93. if r.Local != nil {
  94. params["local"] = strconv.FormatBool(*r.Local)
  95. }
  96. if r.MasterTimeout != 0 {
  97. params["master_timeout"] = formatDuration(r.MasterTimeout)
  98. }
  99. if r.Pretty {
  100. params["pretty"] = "true"
  101. }
  102. if r.Human {
  103. params["human"] = "true"
  104. }
  105. if r.ErrorTrace {
  106. params["error_trace"] = "true"
  107. }
  108. if len(r.FilterPath) > 0 {
  109. params["filter_path"] = strings.Join(r.FilterPath, ",")
  110. }
  111. req, err := newRequest(method, path.String(), nil)
  112. if err != nil {
  113. return nil, err
  114. }
  115. if len(params) > 0 {
  116. q := req.URL.Query()
  117. for k, v := range params {
  118. q.Set(k, v)
  119. }
  120. req.URL.RawQuery = q.Encode()
  121. }
  122. if len(r.Header) > 0 {
  123. if len(req.Header) == 0 {
  124. req.Header = r.Header
  125. } else {
  126. for k, vv := range r.Header {
  127. for _, v := range vv {
  128. req.Header.Add(k, v)
  129. }
  130. }
  131. }
  132. }
  133. if ctx != nil {
  134. req = req.WithContext(ctx)
  135. }
  136. res, err := transport.Perform(req)
  137. if err != nil {
  138. return nil, err
  139. }
  140. response := Response{
  141. StatusCode: res.StatusCode,
  142. Body: res.Body,
  143. Header: res.Header,
  144. }
  145. return &response, nil
  146. }
  147. // WithContext sets the request context.
  148. func (f IndicesGet) WithContext(v context.Context) func(*IndicesGetRequest) {
  149. return func(r *IndicesGetRequest) {
  150. r.ctx = v
  151. }
  152. }
  153. // WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false).
  154. func (f IndicesGet) WithAllowNoIndices(v bool) func(*IndicesGetRequest) {
  155. return func(r *IndicesGetRequest) {
  156. r.AllowNoIndices = &v
  157. }
  158. }
  159. // WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open).
  160. func (f IndicesGet) WithExpandWildcards(v string) func(*IndicesGetRequest) {
  161. return func(r *IndicesGetRequest) {
  162. r.ExpandWildcards = v
  163. }
  164. }
  165. // WithFlatSettings - return settings in flat format (default: false).
  166. func (f IndicesGet) WithFlatSettings(v bool) func(*IndicesGetRequest) {
  167. return func(r *IndicesGetRequest) {
  168. r.FlatSettings = &v
  169. }
  170. }
  171. // WithIgnoreUnavailable - ignore unavailable indexes (default: false).
  172. func (f IndicesGet) WithIgnoreUnavailable(v bool) func(*IndicesGetRequest) {
  173. return func(r *IndicesGetRequest) {
  174. r.IgnoreUnavailable = &v
  175. }
  176. }
  177. // WithIncludeDefaults - whether to return all default setting for each of the indices..
  178. func (f IndicesGet) WithIncludeDefaults(v bool) func(*IndicesGetRequest) {
  179. return func(r *IndicesGetRequest) {
  180. r.IncludeDefaults = &v
  181. }
  182. }
  183. // WithIncludeTypeName - whether to add the type name to the response (default: false).
  184. func (f IndicesGet) WithIncludeTypeName(v bool) func(*IndicesGetRequest) {
  185. return func(r *IndicesGetRequest) {
  186. r.IncludeTypeName = &v
  187. }
  188. }
  189. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  190. func (f IndicesGet) WithLocal(v bool) func(*IndicesGetRequest) {
  191. return func(r *IndicesGetRequest) {
  192. r.Local = &v
  193. }
  194. }
  195. // WithMasterTimeout - specify timeout for connection to master.
  196. func (f IndicesGet) WithMasterTimeout(v time.Duration) func(*IndicesGetRequest) {
  197. return func(r *IndicesGetRequest) {
  198. r.MasterTimeout = v
  199. }
  200. }
  201. // WithPretty makes the response body pretty-printed.
  202. func (f IndicesGet) WithPretty() func(*IndicesGetRequest) {
  203. return func(r *IndicesGetRequest) {
  204. r.Pretty = true
  205. }
  206. }
  207. // WithHuman makes statistical values human-readable.
  208. func (f IndicesGet) WithHuman() func(*IndicesGetRequest) {
  209. return func(r *IndicesGetRequest) {
  210. r.Human = true
  211. }
  212. }
  213. // WithErrorTrace includes the stack trace for errors in the response body.
  214. func (f IndicesGet) WithErrorTrace() func(*IndicesGetRequest) {
  215. return func(r *IndicesGetRequest) {
  216. r.ErrorTrace = true
  217. }
  218. }
  219. // WithFilterPath filters the properties of the response body.
  220. func (f IndicesGet) WithFilterPath(v ...string) func(*IndicesGetRequest) {
  221. return func(r *IndicesGetRequest) {
  222. r.FilterPath = v
  223. }
  224. }
  225. // WithHeader adds the headers to the HTTP request.
  226. func (f IndicesGet) WithHeader(h map[string]string) func(*IndicesGetRequest) {
  227. return func(r *IndicesGetRequest) {
  228. if r.Header == nil {
  229. r.Header = make(http.Header)
  230. }
  231. for k, v := range h {
  232. r.Header.Add(k, v)
  233. }
  234. }
  235. }
  236. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  237. func (f IndicesGet) WithOpaqueID(s string) func(*IndicesGetRequest) {
  238. return func(r *IndicesGetRequest) {
  239. if r.Header == nil {
  240. r.Header = make(http.Header)
  241. }
  242. r.Header.Set("X-Opaque-Id", s)
  243. }
  244. }