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.

indices_delete_component_template.go 5.3KB

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