api.indices.get_mapping.go 7.6 KB

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