You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ingest_delete_pipeline.go 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "context"
  7. "encoding/json"
  8. "fmt"
  9. "net/http"
  10. "net/url"
  11. "strings"
  12. "github.com/olivere/elastic/v7/uritemplates"
  13. )
  14. // IngestDeletePipelineService deletes pipelines by ID.
  15. // It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/7.0/delete-pipeline-api.html.
  16. type IngestDeletePipelineService struct {
  17. client *Client
  18. pretty *bool // pretty format the returned JSON response
  19. human *bool // return human readable values for statistics
  20. errorTrace *bool // include the stack trace of returned errors
  21. filterPath []string // list of filters used to reduce the response
  22. headers http.Header // custom request-level HTTP headers
  23. id string
  24. masterTimeout string
  25. timeout string
  26. }
  27. // NewIngestDeletePipelineService creates a new IngestDeletePipelineService.
  28. func NewIngestDeletePipelineService(client *Client) *IngestDeletePipelineService {
  29. return &IngestDeletePipelineService{
  30. client: client,
  31. }
  32. }
  33. // Pretty tells Elasticsearch whether to return a formatted JSON response.
  34. func (s *IngestDeletePipelineService) Pretty(pretty bool) *IngestDeletePipelineService {
  35. s.pretty = &pretty
  36. return s
  37. }
  38. // Human specifies whether human readable values should be returned in
  39. // the JSON response, e.g. "7.5mb".
  40. func (s *IngestDeletePipelineService) Human(human bool) *IngestDeletePipelineService {
  41. s.human = &human
  42. return s
  43. }
  44. // ErrorTrace specifies whether to include the stack trace of returned errors.
  45. func (s *IngestDeletePipelineService) ErrorTrace(errorTrace bool) *IngestDeletePipelineService {
  46. s.errorTrace = &errorTrace
  47. return s
  48. }
  49. // FilterPath specifies a list of filters used to reduce the response.
  50. func (s *IngestDeletePipelineService) FilterPath(filterPath ...string) *IngestDeletePipelineService {
  51. s.filterPath = filterPath
  52. return s
  53. }
  54. // Header adds a header to the request.
  55. func (s *IngestDeletePipelineService) Header(name string, value string) *IngestDeletePipelineService {
  56. if s.headers == nil {
  57. s.headers = http.Header{}
  58. }
  59. s.headers.Add(name, value)
  60. return s
  61. }
  62. // Headers specifies the headers of the request.
  63. func (s *IngestDeletePipelineService) Headers(headers http.Header) *IngestDeletePipelineService {
  64. s.headers = headers
  65. return s
  66. }
  67. // Id is documented as: Pipeline ID.
  68. func (s *IngestDeletePipelineService) Id(id string) *IngestDeletePipelineService {
  69. s.id = id
  70. return s
  71. }
  72. // MasterTimeout is documented as: Explicit operation timeout for connection to master node.
  73. func (s *IngestDeletePipelineService) MasterTimeout(masterTimeout string) *IngestDeletePipelineService {
  74. s.masterTimeout = masterTimeout
  75. return s
  76. }
  77. // Timeout is documented as: Explicit operation timeout.
  78. func (s *IngestDeletePipelineService) Timeout(timeout string) *IngestDeletePipelineService {
  79. s.timeout = timeout
  80. return s
  81. }
  82. // buildURL builds the URL for the operation.
  83. func (s *IngestDeletePipelineService) buildURL() (string, url.Values, error) {
  84. // Build URL
  85. path, err := uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{
  86. "id": s.id,
  87. })
  88. if err != nil {
  89. return "", url.Values{}, err
  90. }
  91. // Add query string parameters
  92. params := url.Values{}
  93. if v := s.pretty; v != nil {
  94. params.Set("pretty", fmt.Sprint(*v))
  95. }
  96. if v := s.human; v != nil {
  97. params.Set("human", fmt.Sprint(*v))
  98. }
  99. if v := s.errorTrace; v != nil {
  100. params.Set("error_trace", fmt.Sprint(*v))
  101. }
  102. if len(s.filterPath) > 0 {
  103. params.Set("filter_path", strings.Join(s.filterPath, ","))
  104. }
  105. if s.masterTimeout != "" {
  106. params.Set("master_timeout", s.masterTimeout)
  107. }
  108. if s.timeout != "" {
  109. params.Set("timeout", s.timeout)
  110. }
  111. return path, params, nil
  112. }
  113. // Validate checks if the operation is valid.
  114. func (s *IngestDeletePipelineService) Validate() error {
  115. var invalid []string
  116. if s.id == "" {
  117. invalid = append(invalid, "Id")
  118. }
  119. if len(invalid) > 0 {
  120. return fmt.Errorf("missing required fields: %v", invalid)
  121. }
  122. return nil
  123. }
  124. // Do executes the operation.
  125. func (s *IngestDeletePipelineService) Do(ctx context.Context) (*IngestDeletePipelineResponse, error) {
  126. // Check pre-conditions
  127. if err := s.Validate(); err != nil {
  128. return nil, err
  129. }
  130. // Get URL for request
  131. path, params, err := s.buildURL()
  132. if err != nil {
  133. return nil, err
  134. }
  135. // Get HTTP response
  136. res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
  137. Method: "DELETE",
  138. Path: path,
  139. Params: params,
  140. Headers: s.headers,
  141. })
  142. if err != nil {
  143. return nil, err
  144. }
  145. // Return operation response
  146. ret := new(IngestDeletePipelineResponse)
  147. if err := json.Unmarshal(res.Body, ret); err != nil {
  148. return nil, err
  149. }
  150. return ret, nil
  151. }
  152. // IngestDeletePipelineResponse is the response of IngestDeletePipelineService.Do.
  153. type IngestDeletePipelineResponse struct {
  154. Acknowledged bool `json:"acknowledged"`
  155. ShardsAcknowledged bool `json:"shards_acknowledged"`
  156. Index string `json:"index,omitempty"`
  157. }