api.xpack.async_search.delete.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. "strings"
  24. )
  25. func newAsyncSearchDeleteFunc(t Transport) AsyncSearchDelete {
  26. return func(id string, o ...func(*AsyncSearchDeleteRequest)) (*Response, error) {
  27. var r = AsyncSearchDeleteRequest{DocumentID: id}
  28. for _, f := range o {
  29. f(&r)
  30. }
  31. return r.Do(r.ctx, t)
  32. }
  33. }
  34. // ----- API Definition -------------------------------------------------------
  35. // AsyncSearchDelete - Deletes an async search by ID. If the search is still running, the search request will be cancelled. Otherwise, the saved search results are deleted.
  36. //
  37. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html.
  38. type AsyncSearchDelete func(id string, o ...func(*AsyncSearchDeleteRequest)) (*Response, error)
  39. // AsyncSearchDeleteRequest configures the Async Search Delete API request.
  40. type AsyncSearchDeleteRequest struct {
  41. DocumentID string
  42. Pretty bool
  43. Human bool
  44. ErrorTrace bool
  45. FilterPath []string
  46. Header http.Header
  47. ctx context.Context
  48. }
  49. // Do executes the request and returns response or error.
  50. func (r AsyncSearchDeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  51. var (
  52. method string
  53. path strings.Builder
  54. params map[string]string
  55. )
  56. method = "DELETE"
  57. path.Grow(1 + len("_async_search") + 1 + len(r.DocumentID))
  58. path.WriteString("/")
  59. path.WriteString("_async_search")
  60. path.WriteString("/")
  61. path.WriteString(r.DocumentID)
  62. params = make(map[string]string)
  63. if r.Pretty {
  64. params["pretty"] = "true"
  65. }
  66. if r.Human {
  67. params["human"] = "true"
  68. }
  69. if r.ErrorTrace {
  70. params["error_trace"] = "true"
  71. }
  72. if len(r.FilterPath) > 0 {
  73. params["filter_path"] = strings.Join(r.FilterPath, ",")
  74. }
  75. req, err := newRequest(method, path.String(), nil)
  76. if err != nil {
  77. return nil, err
  78. }
  79. if len(params) > 0 {
  80. q := req.URL.Query()
  81. for k, v := range params {
  82. q.Set(k, v)
  83. }
  84. req.URL.RawQuery = q.Encode()
  85. }
  86. if len(r.Header) > 0 {
  87. if len(req.Header) == 0 {
  88. req.Header = r.Header
  89. } else {
  90. for k, vv := range r.Header {
  91. for _, v := range vv {
  92. req.Header.Add(k, v)
  93. }
  94. }
  95. }
  96. }
  97. if ctx != nil {
  98. req = req.WithContext(ctx)
  99. }
  100. res, err := transport.Perform(req)
  101. if err != nil {
  102. return nil, err
  103. }
  104. response := Response{
  105. StatusCode: res.StatusCode,
  106. Body: res.Body,
  107. Header: res.Header,
  108. }
  109. return &response, nil
  110. }
  111. // WithContext sets the request context.
  112. func (f AsyncSearchDelete) WithContext(v context.Context) func(*AsyncSearchDeleteRequest) {
  113. return func(r *AsyncSearchDeleteRequest) {
  114. r.ctx = v
  115. }
  116. }
  117. // WithPretty makes the response body pretty-printed.
  118. func (f AsyncSearchDelete) WithPretty() func(*AsyncSearchDeleteRequest) {
  119. return func(r *AsyncSearchDeleteRequest) {
  120. r.Pretty = true
  121. }
  122. }
  123. // WithHuman makes statistical values human-readable.
  124. func (f AsyncSearchDelete) WithHuman() func(*AsyncSearchDeleteRequest) {
  125. return func(r *AsyncSearchDeleteRequest) {
  126. r.Human = true
  127. }
  128. }
  129. // WithErrorTrace includes the stack trace for errors in the response body.
  130. func (f AsyncSearchDelete) WithErrorTrace() func(*AsyncSearchDeleteRequest) {
  131. return func(r *AsyncSearchDeleteRequest) {
  132. r.ErrorTrace = true
  133. }
  134. }
  135. // WithFilterPath filters the properties of the response body.
  136. func (f AsyncSearchDelete) WithFilterPath(v ...string) func(*AsyncSearchDeleteRequest) {
  137. return func(r *AsyncSearchDeleteRequest) {
  138. r.FilterPath = v
  139. }
  140. }
  141. // WithHeader adds the headers to the HTTP request.
  142. func (f AsyncSearchDelete) WithHeader(h map[string]string) func(*AsyncSearchDeleteRequest) {
  143. return func(r *AsyncSearchDeleteRequest) {
  144. if r.Header == nil {
  145. r.Header = make(http.Header)
  146. }
  147. for k, v := range h {
  148. r.Header.Add(k, v)
  149. }
  150. }
  151. }
  152. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  153. func (f AsyncSearchDelete) WithOpaqueID(s string) func(*AsyncSearchDeleteRequest) {
  154. return func(r *AsyncSearchDeleteRequest) {
  155. if r.Header == nil {
  156. r.Header = make(http.Header)
  157. }
  158. r.Header.Set("X-Opaque-Id", s)
  159. }
  160. }