Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ingest_get_pipeline.go 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // IngestGetPipelineService returns pipelines based on ID.
  15. // See https://www.elastic.co/guide/en/elasticsearch/reference/7.0/get-pipeline-api.html
  16. // for documentation.
  17. type IngestGetPipelineService 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. id []string
  25. masterTimeout string
  26. }
  27. // NewIngestGetPipelineService creates a new IngestGetPipelineService.
  28. func NewIngestGetPipelineService(client *Client) *IngestGetPipelineService {
  29. return &IngestGetPipelineService{
  30. client: client,
  31. }
  32. }
  33. // Pretty tells Elasticsearch whether to return a formatted JSON response.
  34. func (s *IngestGetPipelineService) Pretty(pretty bool) *IngestGetPipelineService {
  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 *IngestGetPipelineService) Human(human bool) *IngestGetPipelineService {
  41. s.human = &human
  42. return s
  43. }
  44. // ErrorTrace specifies whether to include the stack trace of returned errors.
  45. func (s *IngestGetPipelineService) ErrorTrace(errorTrace bool) *IngestGetPipelineService {
  46. s.errorTrace = &errorTrace
  47. return s
  48. }
  49. // FilterPath specifies a list of filters used to reduce the response.
  50. func (s *IngestGetPipelineService) FilterPath(filterPath ...string) *IngestGetPipelineService {
  51. s.filterPath = filterPath
  52. return s
  53. }
  54. // Header adds a header to the request.
  55. func (s *IngestGetPipelineService) Header(name string, value string) *IngestGetPipelineService {
  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 *IngestGetPipelineService) Headers(headers http.Header) *IngestGetPipelineService {
  64. s.headers = headers
  65. return s
  66. }
  67. // Id is a list of pipeline ids. Wildcards supported.
  68. func (s *IngestGetPipelineService) Id(id ...string) *IngestGetPipelineService {
  69. s.id = append(s.id, id...)
  70. return s
  71. }
  72. // MasterTimeout is an explicit operation timeout for connection to master node.
  73. func (s *IngestGetPipelineService) MasterTimeout(masterTimeout string) *IngestGetPipelineService {
  74. s.masterTimeout = masterTimeout
  75. return s
  76. }
  77. // buildURL builds the URL for the operation.
  78. func (s *IngestGetPipelineService) buildURL() (string, url.Values, error) {
  79. var err error
  80. var path string
  81. // Build URL
  82. if len(s.id) > 0 {
  83. path, err = uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{
  84. "id": strings.Join(s.id, ","),
  85. })
  86. } else {
  87. path = "/_ingest/pipeline"
  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.masterTimeout != "" {
  107. params.Set("master_timeout", s.masterTimeout)
  108. }
  109. return path, params, nil
  110. }
  111. // Validate checks if the operation is valid.
  112. func (s *IngestGetPipelineService) Validate() error {
  113. return nil
  114. }
  115. // Do executes the operation.
  116. func (s *IngestGetPipelineService) Do(ctx context.Context) (IngestGetPipelineResponse, error) {
  117. // Check pre-conditions
  118. if err := s.Validate(); err != nil {
  119. return nil, err
  120. }
  121. // Get URL for request
  122. path, params, err := s.buildURL()
  123. if err != nil {
  124. return nil, err
  125. }
  126. // Get HTTP response
  127. res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
  128. Method: "GET",
  129. Path: path,
  130. Params: params,
  131. Headers: s.headers,
  132. })
  133. if err != nil {
  134. return nil, err
  135. }
  136. // Return operation response
  137. var ret IngestGetPipelineResponse
  138. if err := json.Unmarshal(res.Body, &ret); err != nil {
  139. return nil, err
  140. }
  141. return ret, nil
  142. }
  143. // IngestGetPipelineResponse is the response of IngestGetPipelineService.Do.
  144. type IngestGetPipelineResponse map[string]*IngestGetPipeline
  145. // IngestGetPipeline describes a specific ingest pipeline, its
  146. // processors etc.
  147. type IngestGetPipeline struct {
  148. Description string `json:"description"`
  149. Processors []map[string]interface{} `json:"processors"`
  150. Version int64 `json:"version,omitempty"`
  151. OnFailure []map[string]interface{} `json:"on_failure,omitempty"`
  152. }