api.mtermvectors.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. "io"
  23. "net/http"
  24. "strconv"
  25. "strings"
  26. )
  27. func newMtermvectorsFunc(t Transport) Mtermvectors {
  28. return func(o ...func(*MtermvectorsRequest)) (*Response, error) {
  29. var r = MtermvectorsRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // Mtermvectors returns multiple termvectors in one request.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html.
  40. type Mtermvectors func(o ...func(*MtermvectorsRequest)) (*Response, error)
  41. // MtermvectorsRequest configures the Mtermvectors API request.
  42. type MtermvectorsRequest struct {
  43. Index string
  44. DocumentType string
  45. Body io.Reader
  46. Fields []string
  47. FieldStatistics *bool
  48. Ids []string
  49. Offsets *bool
  50. Payloads *bool
  51. Positions *bool
  52. Preference string
  53. Realtime *bool
  54. Routing string
  55. TermStatistics *bool
  56. Version *int
  57. VersionType string
  58. Pretty bool
  59. Human bool
  60. ErrorTrace bool
  61. FilterPath []string
  62. Header http.Header
  63. ctx context.Context
  64. }
  65. // Do executes the request and returns response or error.
  66. func (r MtermvectorsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  67. var (
  68. method string
  69. path strings.Builder
  70. params map[string]string
  71. )
  72. method = "POST"
  73. path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len("_mtermvectors"))
  74. if r.Index != "" {
  75. path.WriteString("/")
  76. path.WriteString(r.Index)
  77. }
  78. if r.DocumentType != "" {
  79. path.WriteString("/")
  80. path.WriteString(r.DocumentType)
  81. }
  82. path.WriteString("/")
  83. path.WriteString("_mtermvectors")
  84. params = make(map[string]string)
  85. if len(r.Fields) > 0 {
  86. params["fields"] = strings.Join(r.Fields, ",")
  87. }
  88. if r.FieldStatistics != nil {
  89. params["field_statistics"] = strconv.FormatBool(*r.FieldStatistics)
  90. }
  91. if len(r.Ids) > 0 {
  92. params["ids"] = strings.Join(r.Ids, ",")
  93. }
  94. if r.Offsets != nil {
  95. params["offsets"] = strconv.FormatBool(*r.Offsets)
  96. }
  97. if r.Payloads != nil {
  98. params["payloads"] = strconv.FormatBool(*r.Payloads)
  99. }
  100. if r.Positions != nil {
  101. params["positions"] = strconv.FormatBool(*r.Positions)
  102. }
  103. if r.Preference != "" {
  104. params["preference"] = r.Preference
  105. }
  106. if r.Realtime != nil {
  107. params["realtime"] = strconv.FormatBool(*r.Realtime)
  108. }
  109. if r.Routing != "" {
  110. params["routing"] = r.Routing
  111. }
  112. if r.TermStatistics != nil {
  113. params["term_statistics"] = strconv.FormatBool(*r.TermStatistics)
  114. }
  115. if r.Version != nil {
  116. params["version"] = strconv.FormatInt(int64(*r.Version), 10)
  117. }
  118. if r.VersionType != "" {
  119. params["version_type"] = r.VersionType
  120. }
  121. if r.Pretty {
  122. params["pretty"] = "true"
  123. }
  124. if r.Human {
  125. params["human"] = "true"
  126. }
  127. if r.ErrorTrace {
  128. params["error_trace"] = "true"
  129. }
  130. if len(r.FilterPath) > 0 {
  131. params["filter_path"] = strings.Join(r.FilterPath, ",")
  132. }
  133. req, err := newRequest(method, path.String(), r.Body)
  134. if err != nil {
  135. return nil, err
  136. }
  137. if len(params) > 0 {
  138. q := req.URL.Query()
  139. for k, v := range params {
  140. q.Set(k, v)
  141. }
  142. req.URL.RawQuery = q.Encode()
  143. }
  144. if len(r.Header) > 0 {
  145. if len(req.Header) == 0 {
  146. req.Header = r.Header
  147. } else {
  148. for k, vv := range r.Header {
  149. for _, v := range vv {
  150. req.Header.Add(k, v)
  151. }
  152. }
  153. }
  154. }
  155. if r.Body != nil && req.Header.Get(headerContentType) == "" {
  156. req.Header[headerContentType] = headerContentTypeJSON
  157. }
  158. if ctx != nil {
  159. req = req.WithContext(ctx)
  160. }
  161. res, err := transport.Perform(req)
  162. if err != nil {
  163. return nil, err
  164. }
  165. response := Response{
  166. StatusCode: res.StatusCode,
  167. Body: res.Body,
  168. Header: res.Header,
  169. }
  170. return &response, nil
  171. }
  172. // WithContext sets the request context.
  173. func (f Mtermvectors) WithContext(v context.Context) func(*MtermvectorsRequest) {
  174. return func(r *MtermvectorsRequest) {
  175. r.ctx = v
  176. }
  177. }
  178. // WithBody - Define ids, documents, parameters or a list of parameters per document here. You must at least provide a list of document ids. See documentation..
  179. func (f Mtermvectors) WithBody(v io.Reader) func(*MtermvectorsRequest) {
  180. return func(r *MtermvectorsRequest) {
  181. r.Body = v
  182. }
  183. }
  184. // WithIndex - the index in which the document resides..
  185. func (f Mtermvectors) WithIndex(v string) func(*MtermvectorsRequest) {
  186. return func(r *MtermvectorsRequest) {
  187. r.Index = v
  188. }
  189. }
  190. // WithDocumentType - the type of the document..
  191. func (f Mtermvectors) WithDocumentType(v string) func(*MtermvectorsRequest) {
  192. return func(r *MtermvectorsRequest) {
  193. r.DocumentType = v
  194. }
  195. }
  196. // WithFields - a list of fields to return. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  197. func (f Mtermvectors) WithFields(v ...string) func(*MtermvectorsRequest) {
  198. return func(r *MtermvectorsRequest) {
  199. r.Fields = v
  200. }
  201. }
  202. // WithFieldStatistics - specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  203. func (f Mtermvectors) WithFieldStatistics(v bool) func(*MtermvectorsRequest) {
  204. return func(r *MtermvectorsRequest) {
  205. r.FieldStatistics = &v
  206. }
  207. }
  208. // WithIds - a list of documents ids. you must define ids as parameter or set "ids" or "docs" in the request body.
  209. func (f Mtermvectors) WithIds(v ...string) func(*MtermvectorsRequest) {
  210. return func(r *MtermvectorsRequest) {
  211. r.Ids = v
  212. }
  213. }
  214. // WithOffsets - specifies if term offsets should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  215. func (f Mtermvectors) WithOffsets(v bool) func(*MtermvectorsRequest) {
  216. return func(r *MtermvectorsRequest) {
  217. r.Offsets = &v
  218. }
  219. }
  220. // WithPayloads - specifies if term payloads should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  221. func (f Mtermvectors) WithPayloads(v bool) func(*MtermvectorsRequest) {
  222. return func(r *MtermvectorsRequest) {
  223. r.Payloads = &v
  224. }
  225. }
  226. // WithPositions - specifies if term positions should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  227. func (f Mtermvectors) WithPositions(v bool) func(*MtermvectorsRequest) {
  228. return func(r *MtermvectorsRequest) {
  229. r.Positions = &v
  230. }
  231. }
  232. // WithPreference - specify the node or shard the operation should be performed on (default: random) .applies to all returned documents unless otherwise specified in body "params" or "docs"..
  233. func (f Mtermvectors) WithPreference(v string) func(*MtermvectorsRequest) {
  234. return func(r *MtermvectorsRequest) {
  235. r.Preference = v
  236. }
  237. }
  238. // WithRealtime - specifies if requests are real-time as opposed to near-real-time (default: true)..
  239. func (f Mtermvectors) WithRealtime(v bool) func(*MtermvectorsRequest) {
  240. return func(r *MtermvectorsRequest) {
  241. r.Realtime = &v
  242. }
  243. }
  244. // WithRouting - specific routing value. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  245. func (f Mtermvectors) WithRouting(v string) func(*MtermvectorsRequest) {
  246. return func(r *MtermvectorsRequest) {
  247. r.Routing = v
  248. }
  249. }
  250. // WithTermStatistics - specifies if total term frequency and document frequency should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs"..
  251. func (f Mtermvectors) WithTermStatistics(v bool) func(*MtermvectorsRequest) {
  252. return func(r *MtermvectorsRequest) {
  253. r.TermStatistics = &v
  254. }
  255. }
  256. // WithVersion - explicit version number for concurrency control.
  257. func (f Mtermvectors) WithVersion(v int) func(*MtermvectorsRequest) {
  258. return func(r *MtermvectorsRequest) {
  259. r.Version = &v
  260. }
  261. }
  262. // WithVersionType - specific version type.
  263. func (f Mtermvectors) WithVersionType(v string) func(*MtermvectorsRequest) {
  264. return func(r *MtermvectorsRequest) {
  265. r.VersionType = v
  266. }
  267. }
  268. // WithPretty makes the response body pretty-printed.
  269. func (f Mtermvectors) WithPretty() func(*MtermvectorsRequest) {
  270. return func(r *MtermvectorsRequest) {
  271. r.Pretty = true
  272. }
  273. }
  274. // WithHuman makes statistical values human-readable.
  275. func (f Mtermvectors) WithHuman() func(*MtermvectorsRequest) {
  276. return func(r *MtermvectorsRequest) {
  277. r.Human = true
  278. }
  279. }
  280. // WithErrorTrace includes the stack trace for errors in the response body.
  281. func (f Mtermvectors) WithErrorTrace() func(*MtermvectorsRequest) {
  282. return func(r *MtermvectorsRequest) {
  283. r.ErrorTrace = true
  284. }
  285. }
  286. // WithFilterPath filters the properties of the response body.
  287. func (f Mtermvectors) WithFilterPath(v ...string) func(*MtermvectorsRequest) {
  288. return func(r *MtermvectorsRequest) {
  289. r.FilterPath = v
  290. }
  291. }
  292. // WithHeader adds the headers to the HTTP request.
  293. func (f Mtermvectors) WithHeader(h map[string]string) func(*MtermvectorsRequest) {
  294. return func(r *MtermvectorsRequest) {
  295. if r.Header == nil {
  296. r.Header = make(http.Header)
  297. }
  298. for k, v := range h {
  299. r.Header.Add(k, v)
  300. }
  301. }
  302. }
  303. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  304. func (f Mtermvectors) WithOpaqueID(s string) func(*MtermvectorsRequest) {
  305. return func(r *MtermvectorsRequest) {
  306. if r.Header == nil {
  307. r.Header = make(http.Header)
  308. }
  309. r.Header.Set("X-Opaque-Id", s)
  310. }
  311. }