api.xpack.async_search.submit.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. "time"
  27. )
  28. func newAsyncSearchSubmitFunc(t Transport) AsyncSearchSubmit {
  29. return func(o ...func(*AsyncSearchSubmitRequest)) (*Response, error) {
  30. var r = AsyncSearchSubmitRequest{}
  31. for _, f := range o {
  32. f(&r)
  33. }
  34. return r.Do(r.ctx, t)
  35. }
  36. }
  37. // ----- API Definition -------------------------------------------------------
  38. // AsyncSearchSubmit - Executes a search request asynchronously.
  39. //
  40. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html.
  41. type AsyncSearchSubmit func(o ...func(*AsyncSearchSubmitRequest)) (*Response, error)
  42. // AsyncSearchSubmitRequest configures the Async Search Submit API request.
  43. type AsyncSearchSubmitRequest struct {
  44. Index []string
  45. Body io.Reader
  46. AllowNoIndices *bool
  47. AllowPartialSearchResults *bool
  48. Analyzer string
  49. AnalyzeWildcard *bool
  50. BatchedReduceSize *int
  51. DefaultOperator string
  52. Df string
  53. DocvalueFields []string
  54. ExpandWildcards string
  55. Explain *bool
  56. From *int
  57. IgnoreThrottled *bool
  58. IgnoreUnavailable *bool
  59. KeepAlive time.Duration
  60. KeepOnCompletion *bool
  61. Lenient *bool
  62. MaxConcurrentShardRequests *int
  63. Preference string
  64. Query string
  65. RequestCache *bool
  66. Routing []string
  67. SearchType string
  68. SeqNoPrimaryTerm *bool
  69. Size *int
  70. Sort []string
  71. Source []string
  72. SourceExcludes []string
  73. SourceIncludes []string
  74. Stats []string
  75. StoredFields []string
  76. SuggestField string
  77. SuggestMode string
  78. SuggestSize *int
  79. SuggestText string
  80. TerminateAfter *int
  81. Timeout time.Duration
  82. TrackScores *bool
  83. TrackTotalHits *bool
  84. TypedKeys *bool
  85. Version *bool
  86. WaitForCompletionTimeout time.Duration
  87. Pretty bool
  88. Human bool
  89. ErrorTrace bool
  90. FilterPath []string
  91. Header http.Header
  92. ctx context.Context
  93. }
  94. // Do executes the request and returns response or error.
  95. func (r AsyncSearchSubmitRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  96. var (
  97. method string
  98. path strings.Builder
  99. params map[string]string
  100. )
  101. method = "POST"
  102. path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_async_search"))
  103. if len(r.Index) > 0 {
  104. path.WriteString("/")
  105. path.WriteString(strings.Join(r.Index, ","))
  106. }
  107. path.WriteString("/")
  108. path.WriteString("_async_search")
  109. params = make(map[string]string)
  110. if r.AllowNoIndices != nil {
  111. params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
  112. }
  113. if r.AllowPartialSearchResults != nil {
  114. params["allow_partial_search_results"] = strconv.FormatBool(*r.AllowPartialSearchResults)
  115. }
  116. if r.Analyzer != "" {
  117. params["analyzer"] = r.Analyzer
  118. }
  119. if r.AnalyzeWildcard != nil {
  120. params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard)
  121. }
  122. if r.BatchedReduceSize != nil {
  123. params["batched_reduce_size"] = strconv.FormatInt(int64(*r.BatchedReduceSize), 10)
  124. }
  125. if r.DefaultOperator != "" {
  126. params["default_operator"] = r.DefaultOperator
  127. }
  128. if r.Df != "" {
  129. params["df"] = r.Df
  130. }
  131. if len(r.DocvalueFields) > 0 {
  132. params["docvalue_fields"] = strings.Join(r.DocvalueFields, ",")
  133. }
  134. if r.ExpandWildcards != "" {
  135. params["expand_wildcards"] = r.ExpandWildcards
  136. }
  137. if r.Explain != nil {
  138. params["explain"] = strconv.FormatBool(*r.Explain)
  139. }
  140. if r.From != nil {
  141. params["from"] = strconv.FormatInt(int64(*r.From), 10)
  142. }
  143. if r.IgnoreThrottled != nil {
  144. params["ignore_throttled"] = strconv.FormatBool(*r.IgnoreThrottled)
  145. }
  146. if r.IgnoreUnavailable != nil {
  147. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  148. }
  149. if r.KeepAlive != 0 {
  150. params["keep_alive"] = formatDuration(r.KeepAlive)
  151. }
  152. if r.KeepOnCompletion != nil {
  153. params["keep_on_completion"] = strconv.FormatBool(*r.KeepOnCompletion)
  154. }
  155. if r.Lenient != nil {
  156. params["lenient"] = strconv.FormatBool(*r.Lenient)
  157. }
  158. if r.MaxConcurrentShardRequests != nil {
  159. params["max_concurrent_shard_requests"] = strconv.FormatInt(int64(*r.MaxConcurrentShardRequests), 10)
  160. }
  161. if r.Preference != "" {
  162. params["preference"] = r.Preference
  163. }
  164. if r.Query != "" {
  165. params["q"] = r.Query
  166. }
  167. if r.RequestCache != nil {
  168. params["request_cache"] = strconv.FormatBool(*r.RequestCache)
  169. }
  170. if len(r.Routing) > 0 {
  171. params["routing"] = strings.Join(r.Routing, ",")
  172. }
  173. if r.SearchType != "" {
  174. params["search_type"] = r.SearchType
  175. }
  176. if r.SeqNoPrimaryTerm != nil {
  177. params["seq_no_primary_term"] = strconv.FormatBool(*r.SeqNoPrimaryTerm)
  178. }
  179. if r.Size != nil {
  180. params["size"] = strconv.FormatInt(int64(*r.Size), 10)
  181. }
  182. if len(r.Sort) > 0 {
  183. params["sort"] = strings.Join(r.Sort, ",")
  184. }
  185. if len(r.Source) > 0 {
  186. params["_source"] = strings.Join(r.Source, ",")
  187. }
  188. if len(r.SourceExcludes) > 0 {
  189. params["_source_excludes"] = strings.Join(r.SourceExcludes, ",")
  190. }
  191. if len(r.SourceIncludes) > 0 {
  192. params["_source_includes"] = strings.Join(r.SourceIncludes, ",")
  193. }
  194. if len(r.Stats) > 0 {
  195. params["stats"] = strings.Join(r.Stats, ",")
  196. }
  197. if len(r.StoredFields) > 0 {
  198. params["stored_fields"] = strings.Join(r.StoredFields, ",")
  199. }
  200. if r.SuggestField != "" {
  201. params["suggest_field"] = r.SuggestField
  202. }
  203. if r.SuggestMode != "" {
  204. params["suggest_mode"] = r.SuggestMode
  205. }
  206. if r.SuggestSize != nil {
  207. params["suggest_size"] = strconv.FormatInt(int64(*r.SuggestSize), 10)
  208. }
  209. if r.SuggestText != "" {
  210. params["suggest_text"] = r.SuggestText
  211. }
  212. if r.TerminateAfter != nil {
  213. params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10)
  214. }
  215. if r.Timeout != 0 {
  216. params["timeout"] = formatDuration(r.Timeout)
  217. }
  218. if r.TrackScores != nil {
  219. params["track_scores"] = strconv.FormatBool(*r.TrackScores)
  220. }
  221. if r.TrackTotalHits != nil {
  222. params["track_total_hits"] = strconv.FormatBool(*r.TrackTotalHits)
  223. }
  224. if r.TypedKeys != nil {
  225. params["typed_keys"] = strconv.FormatBool(*r.TypedKeys)
  226. }
  227. if r.Version != nil {
  228. params["version"] = strconv.FormatBool(*r.Version)
  229. }
  230. if r.WaitForCompletionTimeout != 0 {
  231. params["wait_for_completion_timeout"] = formatDuration(r.WaitForCompletionTimeout)
  232. }
  233. if r.Pretty {
  234. params["pretty"] = "true"
  235. }
  236. if r.Human {
  237. params["human"] = "true"
  238. }
  239. if r.ErrorTrace {
  240. params["error_trace"] = "true"
  241. }
  242. if len(r.FilterPath) > 0 {
  243. params["filter_path"] = strings.Join(r.FilterPath, ",")
  244. }
  245. req, err := newRequest(method, path.String(), r.Body)
  246. if err != nil {
  247. return nil, err
  248. }
  249. if len(params) > 0 {
  250. q := req.URL.Query()
  251. for k, v := range params {
  252. q.Set(k, v)
  253. }
  254. req.URL.RawQuery = q.Encode()
  255. }
  256. if len(r.Header) > 0 {
  257. if len(req.Header) == 0 {
  258. req.Header = r.Header
  259. } else {
  260. for k, vv := range r.Header {
  261. for _, v := range vv {
  262. req.Header.Add(k, v)
  263. }
  264. }
  265. }
  266. }
  267. if r.Body != nil && req.Header.Get(headerContentType) == "" {
  268. req.Header[headerContentType] = headerContentTypeJSON
  269. }
  270. if ctx != nil {
  271. req = req.WithContext(ctx)
  272. }
  273. res, err := transport.Perform(req)
  274. if err != nil {
  275. return nil, err
  276. }
  277. response := Response{
  278. StatusCode: res.StatusCode,
  279. Body: res.Body,
  280. Header: res.Header,
  281. }
  282. return &response, nil
  283. }
  284. // WithContext sets the request context.
  285. func (f AsyncSearchSubmit) WithContext(v context.Context) func(*AsyncSearchSubmitRequest) {
  286. return func(r *AsyncSearchSubmitRequest) {
  287. r.ctx = v
  288. }
  289. }
  290. // WithBody - The search definition using the Query DSL.
  291. func (f AsyncSearchSubmit) WithBody(v io.Reader) func(*AsyncSearchSubmitRequest) {
  292. return func(r *AsyncSearchSubmitRequest) {
  293. r.Body = v
  294. }
  295. }
  296. // WithIndex - a list of index names to search; use _all to perform the operation on all indices.
  297. func (f AsyncSearchSubmit) WithIndex(v ...string) func(*AsyncSearchSubmitRequest) {
  298. return func(r *AsyncSearchSubmitRequest) {
  299. r.Index = v
  300. }
  301. }
  302. // 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).
  303. func (f AsyncSearchSubmit) WithAllowNoIndices(v bool) func(*AsyncSearchSubmitRequest) {
  304. return func(r *AsyncSearchSubmitRequest) {
  305. r.AllowNoIndices = &v
  306. }
  307. }
  308. // WithAllowPartialSearchResults - indicate if an error should be returned if there is a partial search failure or timeout.
  309. func (f AsyncSearchSubmit) WithAllowPartialSearchResults(v bool) func(*AsyncSearchSubmitRequest) {
  310. return func(r *AsyncSearchSubmitRequest) {
  311. r.AllowPartialSearchResults = &v
  312. }
  313. }
  314. // WithAnalyzer - the analyzer to use for the query string.
  315. func (f AsyncSearchSubmit) WithAnalyzer(v string) func(*AsyncSearchSubmitRequest) {
  316. return func(r *AsyncSearchSubmitRequest) {
  317. r.Analyzer = v
  318. }
  319. }
  320. // WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false).
  321. func (f AsyncSearchSubmit) WithAnalyzeWildcard(v bool) func(*AsyncSearchSubmitRequest) {
  322. return func(r *AsyncSearchSubmitRequest) {
  323. r.AnalyzeWildcard = &v
  324. }
  325. }
  326. // WithBatchedReduceSize - the number of shard results that should be reduced at once on the coordinating node. this value should be used as the granularity at which progress results will be made available..
  327. func (f AsyncSearchSubmit) WithBatchedReduceSize(v int) func(*AsyncSearchSubmitRequest) {
  328. return func(r *AsyncSearchSubmitRequest) {
  329. r.BatchedReduceSize = &v
  330. }
  331. }
  332. // WithDefaultOperator - the default operator for query string query (and or or).
  333. func (f AsyncSearchSubmit) WithDefaultOperator(v string) func(*AsyncSearchSubmitRequest) {
  334. return func(r *AsyncSearchSubmitRequest) {
  335. r.DefaultOperator = v
  336. }
  337. }
  338. // WithDf - the field to use as default where no field prefix is given in the query string.
  339. func (f AsyncSearchSubmit) WithDf(v string) func(*AsyncSearchSubmitRequest) {
  340. return func(r *AsyncSearchSubmitRequest) {
  341. r.Df = v
  342. }
  343. }
  344. // WithDocvalueFields - a list of fields to return as the docvalue representation of a field for each hit.
  345. func (f AsyncSearchSubmit) WithDocvalueFields(v ...string) func(*AsyncSearchSubmitRequest) {
  346. return func(r *AsyncSearchSubmitRequest) {
  347. r.DocvalueFields = v
  348. }
  349. }
  350. // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both..
  351. func (f AsyncSearchSubmit) WithExpandWildcards(v string) func(*AsyncSearchSubmitRequest) {
  352. return func(r *AsyncSearchSubmitRequest) {
  353. r.ExpandWildcards = v
  354. }
  355. }
  356. // WithExplain - specify whether to return detailed information about score computation as part of a hit.
  357. func (f AsyncSearchSubmit) WithExplain(v bool) func(*AsyncSearchSubmitRequest) {
  358. return func(r *AsyncSearchSubmitRequest) {
  359. r.Explain = &v
  360. }
  361. }
  362. // WithFrom - starting offset (default: 0).
  363. func (f AsyncSearchSubmit) WithFrom(v int) func(*AsyncSearchSubmitRequest) {
  364. return func(r *AsyncSearchSubmitRequest) {
  365. r.From = &v
  366. }
  367. }
  368. // WithIgnoreThrottled - whether specified concrete, expanded or aliased indices should be ignored when throttled.
  369. func (f AsyncSearchSubmit) WithIgnoreThrottled(v bool) func(*AsyncSearchSubmitRequest) {
  370. return func(r *AsyncSearchSubmitRequest) {
  371. r.IgnoreThrottled = &v
  372. }
  373. }
  374. // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed).
  375. func (f AsyncSearchSubmit) WithIgnoreUnavailable(v bool) func(*AsyncSearchSubmitRequest) {
  376. return func(r *AsyncSearchSubmitRequest) {
  377. r.IgnoreUnavailable = &v
  378. }
  379. }
  380. // WithKeepAlive - update the time interval in which the results (partial or final) for this search will be available.
  381. func (f AsyncSearchSubmit) WithKeepAlive(v time.Duration) func(*AsyncSearchSubmitRequest) {
  382. return func(r *AsyncSearchSubmitRequest) {
  383. r.KeepAlive = v
  384. }
  385. }
  386. // WithKeepOnCompletion - control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false).
  387. func (f AsyncSearchSubmit) WithKeepOnCompletion(v bool) func(*AsyncSearchSubmitRequest) {
  388. return func(r *AsyncSearchSubmitRequest) {
  389. r.KeepOnCompletion = &v
  390. }
  391. }
  392. // WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored.
  393. func (f AsyncSearchSubmit) WithLenient(v bool) func(*AsyncSearchSubmitRequest) {
  394. return func(r *AsyncSearchSubmitRequest) {
  395. r.Lenient = &v
  396. }
  397. }
  398. // WithMaxConcurrentShardRequests - the number of concurrent shard requests per node this search executes concurrently. this value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests.
  399. func (f AsyncSearchSubmit) WithMaxConcurrentShardRequests(v int) func(*AsyncSearchSubmitRequest) {
  400. return func(r *AsyncSearchSubmitRequest) {
  401. r.MaxConcurrentShardRequests = &v
  402. }
  403. }
  404. // WithPreference - specify the node or shard the operation should be performed on (default: random).
  405. func (f AsyncSearchSubmit) WithPreference(v string) func(*AsyncSearchSubmitRequest) {
  406. return func(r *AsyncSearchSubmitRequest) {
  407. r.Preference = v
  408. }
  409. }
  410. // WithQuery - query in the lucene query string syntax.
  411. func (f AsyncSearchSubmit) WithQuery(v string) func(*AsyncSearchSubmitRequest) {
  412. return func(r *AsyncSearchSubmitRequest) {
  413. r.Query = v
  414. }
  415. }
  416. // WithRequestCache - specify if request cache should be used for this request or not, defaults to true.
  417. func (f AsyncSearchSubmit) WithRequestCache(v bool) func(*AsyncSearchSubmitRequest) {
  418. return func(r *AsyncSearchSubmitRequest) {
  419. r.RequestCache = &v
  420. }
  421. }
  422. // WithRouting - a list of specific routing values.
  423. func (f AsyncSearchSubmit) WithRouting(v ...string) func(*AsyncSearchSubmitRequest) {
  424. return func(r *AsyncSearchSubmitRequest) {
  425. r.Routing = v
  426. }
  427. }
  428. // WithSearchType - search operation type.
  429. func (f AsyncSearchSubmit) WithSearchType(v string) func(*AsyncSearchSubmitRequest) {
  430. return func(r *AsyncSearchSubmitRequest) {
  431. r.SearchType = v
  432. }
  433. }
  434. // WithSeqNoPrimaryTerm - specify whether to return sequence number and primary term of the last modification of each hit.
  435. func (f AsyncSearchSubmit) WithSeqNoPrimaryTerm(v bool) func(*AsyncSearchSubmitRequest) {
  436. return func(r *AsyncSearchSubmitRequest) {
  437. r.SeqNoPrimaryTerm = &v
  438. }
  439. }
  440. // WithSize - number of hits to return (default: 10).
  441. func (f AsyncSearchSubmit) WithSize(v int) func(*AsyncSearchSubmitRequest) {
  442. return func(r *AsyncSearchSubmitRequest) {
  443. r.Size = &v
  444. }
  445. }
  446. // WithSort - a list of <field>:<direction> pairs.
  447. func (f AsyncSearchSubmit) WithSort(v ...string) func(*AsyncSearchSubmitRequest) {
  448. return func(r *AsyncSearchSubmitRequest) {
  449. r.Sort = v
  450. }
  451. }
  452. // WithSource - true or false to return the _source field or not, or a list of fields to return.
  453. func (f AsyncSearchSubmit) WithSource(v ...string) func(*AsyncSearchSubmitRequest) {
  454. return func(r *AsyncSearchSubmitRequest) {
  455. r.Source = v
  456. }
  457. }
  458. // WithSourceExcludes - a list of fields to exclude from the returned _source field.
  459. func (f AsyncSearchSubmit) WithSourceExcludes(v ...string) func(*AsyncSearchSubmitRequest) {
  460. return func(r *AsyncSearchSubmitRequest) {
  461. r.SourceExcludes = v
  462. }
  463. }
  464. // WithSourceIncludes - a list of fields to extract and return from the _source field.
  465. func (f AsyncSearchSubmit) WithSourceIncludes(v ...string) func(*AsyncSearchSubmitRequest) {
  466. return func(r *AsyncSearchSubmitRequest) {
  467. r.SourceIncludes = v
  468. }
  469. }
  470. // WithStats - specific 'tag' of the request for logging and statistical purposes.
  471. func (f AsyncSearchSubmit) WithStats(v ...string) func(*AsyncSearchSubmitRequest) {
  472. return func(r *AsyncSearchSubmitRequest) {
  473. r.Stats = v
  474. }
  475. }
  476. // WithStoredFields - a list of stored fields to return as part of a hit.
  477. func (f AsyncSearchSubmit) WithStoredFields(v ...string) func(*AsyncSearchSubmitRequest) {
  478. return func(r *AsyncSearchSubmitRequest) {
  479. r.StoredFields = v
  480. }
  481. }
  482. // WithSuggestField - specify which field to use for suggestions.
  483. func (f AsyncSearchSubmit) WithSuggestField(v string) func(*AsyncSearchSubmitRequest) {
  484. return func(r *AsyncSearchSubmitRequest) {
  485. r.SuggestField = v
  486. }
  487. }
  488. // WithSuggestMode - specify suggest mode.
  489. func (f AsyncSearchSubmit) WithSuggestMode(v string) func(*AsyncSearchSubmitRequest) {
  490. return func(r *AsyncSearchSubmitRequest) {
  491. r.SuggestMode = v
  492. }
  493. }
  494. // WithSuggestSize - how many suggestions to return in response.
  495. func (f AsyncSearchSubmit) WithSuggestSize(v int) func(*AsyncSearchSubmitRequest) {
  496. return func(r *AsyncSearchSubmitRequest) {
  497. r.SuggestSize = &v
  498. }
  499. }
  500. // WithSuggestText - the source text for which the suggestions should be returned.
  501. func (f AsyncSearchSubmit) WithSuggestText(v string) func(*AsyncSearchSubmitRequest) {
  502. return func(r *AsyncSearchSubmitRequest) {
  503. r.SuggestText = v
  504. }
  505. }
  506. // WithTerminateAfter - the maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early..
  507. func (f AsyncSearchSubmit) WithTerminateAfter(v int) func(*AsyncSearchSubmitRequest) {
  508. return func(r *AsyncSearchSubmitRequest) {
  509. r.TerminateAfter = &v
  510. }
  511. }
  512. // WithTimeout - explicit operation timeout.
  513. func (f AsyncSearchSubmit) WithTimeout(v time.Duration) func(*AsyncSearchSubmitRequest) {
  514. return func(r *AsyncSearchSubmitRequest) {
  515. r.Timeout = v
  516. }
  517. }
  518. // WithTrackScores - whether to calculate and return scores even if they are not used for sorting.
  519. func (f AsyncSearchSubmit) WithTrackScores(v bool) func(*AsyncSearchSubmitRequest) {
  520. return func(r *AsyncSearchSubmitRequest) {
  521. r.TrackScores = &v
  522. }
  523. }
  524. // WithTrackTotalHits - indicate if the number of documents that match the query should be tracked.
  525. func (f AsyncSearchSubmit) WithTrackTotalHits(v bool) func(*AsyncSearchSubmitRequest) {
  526. return func(r *AsyncSearchSubmitRequest) {
  527. r.TrackTotalHits = &v
  528. }
  529. }
  530. // WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response.
  531. func (f AsyncSearchSubmit) WithTypedKeys(v bool) func(*AsyncSearchSubmitRequest) {
  532. return func(r *AsyncSearchSubmitRequest) {
  533. r.TypedKeys = &v
  534. }
  535. }
  536. // WithVersion - specify whether to return document version as part of a hit.
  537. func (f AsyncSearchSubmit) WithVersion(v bool) func(*AsyncSearchSubmitRequest) {
  538. return func(r *AsyncSearchSubmitRequest) {
  539. r.Version = &v
  540. }
  541. }
  542. // WithWaitForCompletionTimeout - specify the time that the request should block waiting for the final response.
  543. func (f AsyncSearchSubmit) WithWaitForCompletionTimeout(v time.Duration) func(*AsyncSearchSubmitRequest) {
  544. return func(r *AsyncSearchSubmitRequest) {
  545. r.WaitForCompletionTimeout = v
  546. }
  547. }
  548. // WithPretty makes the response body pretty-printed.
  549. func (f AsyncSearchSubmit) WithPretty() func(*AsyncSearchSubmitRequest) {
  550. return func(r *AsyncSearchSubmitRequest) {
  551. r.Pretty = true
  552. }
  553. }
  554. // WithHuman makes statistical values human-readable.
  555. func (f AsyncSearchSubmit) WithHuman() func(*AsyncSearchSubmitRequest) {
  556. return func(r *AsyncSearchSubmitRequest) {
  557. r.Human = true
  558. }
  559. }
  560. // WithErrorTrace includes the stack trace for errors in the response body.
  561. func (f AsyncSearchSubmit) WithErrorTrace() func(*AsyncSearchSubmitRequest) {
  562. return func(r *AsyncSearchSubmitRequest) {
  563. r.ErrorTrace = true
  564. }
  565. }
  566. // WithFilterPath filters the properties of the response body.
  567. func (f AsyncSearchSubmit) WithFilterPath(v ...string) func(*AsyncSearchSubmitRequest) {
  568. return func(r *AsyncSearchSubmitRequest) {
  569. r.FilterPath = v
  570. }
  571. }
  572. // WithHeader adds the headers to the HTTP request.
  573. func (f AsyncSearchSubmit) WithHeader(h map[string]string) func(*AsyncSearchSubmitRequest) {
  574. return func(r *AsyncSearchSubmitRequest) {
  575. if r.Header == nil {
  576. r.Header = make(http.Header)
  577. }
  578. for k, v := range h {
  579. r.Header.Add(k, v)
  580. }
  581. }
  582. }
  583. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  584. func (f AsyncSearchSubmit) WithOpaqueID(s string) func(*AsyncSearchSubmitRequest) {
  585. return func(r *AsyncSearchSubmitRequest) {
  586. if r.Header == nil {
  587. r.Header = make(http.Header)
  588. }
  589. r.Header.Set("X-Opaque-Id", s)
  590. }
  591. }