ingest_delete_pipeline.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/url"
  10. "gopkg.in/olivere/elastic.v5/uritemplates"
  11. )
  12. // IngestDeletePipelineService deletes pipelines by ID.
  13. // It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/delete-pipeline-api.html.
  14. type IngestDeletePipelineService struct {
  15. client *Client
  16. pretty bool
  17. id string
  18. masterTimeout string
  19. timeout string
  20. }
  21. // NewIngestDeletePipelineService creates a new IngestDeletePipelineService.
  22. func NewIngestDeletePipelineService(client *Client) *IngestDeletePipelineService {
  23. return &IngestDeletePipelineService{
  24. client: client,
  25. }
  26. }
  27. // Id is documented as: Pipeline ID.
  28. func (s *IngestDeletePipelineService) Id(id string) *IngestDeletePipelineService {
  29. s.id = id
  30. return s
  31. }
  32. // MasterTimeout is documented as: Explicit operation timeout for connection to master node.
  33. func (s *IngestDeletePipelineService) MasterTimeout(masterTimeout string) *IngestDeletePipelineService {
  34. s.masterTimeout = masterTimeout
  35. return s
  36. }
  37. // Timeout is documented as: Explicit operation timeout.
  38. func (s *IngestDeletePipelineService) Timeout(timeout string) *IngestDeletePipelineService {
  39. s.timeout = timeout
  40. return s
  41. }
  42. // Pretty indicates that the JSON response be indented and human readable.
  43. func (s *IngestDeletePipelineService) Pretty(pretty bool) *IngestDeletePipelineService {
  44. s.pretty = pretty
  45. return s
  46. }
  47. // buildURL builds the URL for the operation.
  48. func (s *IngestDeletePipelineService) buildURL() (string, url.Values, error) {
  49. // Build URL
  50. path, err := uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{
  51. "id": s.id,
  52. })
  53. if err != nil {
  54. return "", url.Values{}, err
  55. }
  56. // Add query string parameters
  57. params := url.Values{}
  58. if s.pretty {
  59. params.Set("pretty", "1")
  60. }
  61. if s.masterTimeout != "" {
  62. params.Set("master_timeout", s.masterTimeout)
  63. }
  64. if s.timeout != "" {
  65. params.Set("timeout", s.timeout)
  66. }
  67. return path, params, nil
  68. }
  69. // Validate checks if the operation is valid.
  70. func (s *IngestDeletePipelineService) Validate() error {
  71. var invalid []string
  72. if s.id == "" {
  73. invalid = append(invalid, "Id")
  74. }
  75. if len(invalid) > 0 {
  76. return fmt.Errorf("missing required fields: %v", invalid)
  77. }
  78. return nil
  79. }
  80. // Do executes the operation.
  81. func (s *IngestDeletePipelineService) Do(ctx context.Context) (*IngestDeletePipelineResponse, error) {
  82. // Check pre-conditions
  83. if err := s.Validate(); err != nil {
  84. return nil, err
  85. }
  86. // Get URL for request
  87. path, params, err := s.buildURL()
  88. if err != nil {
  89. return nil, err
  90. }
  91. // Get HTTP response
  92. res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil)
  93. if err != nil {
  94. return nil, err
  95. }
  96. // Return operation response
  97. ret := new(IngestDeletePipelineResponse)
  98. if err := json.Unmarshal(res.Body, ret); err != nil {
  99. return nil, err
  100. }
  101. return ret, nil
  102. }
  103. // IngestDeletePipelineResponse is the response of IngestDeletePipelineService.Do.
  104. type IngestDeletePipelineResponse struct {
  105. Acknowledged bool `json:"acknowledged"`
  106. }