delete_index.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2012-2015 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. "encoding/json"
  7. "github.com/olivere/elastic/uritemplates"
  8. )
  9. type DeleteIndexService struct {
  10. client *Client
  11. index string
  12. }
  13. func NewDeleteIndexService(client *Client) *DeleteIndexService {
  14. builder := &DeleteIndexService{
  15. client: client,
  16. }
  17. return builder
  18. }
  19. func (b *DeleteIndexService) Index(index string) *DeleteIndexService {
  20. b.index = index
  21. return b
  22. }
  23. func (b *DeleteIndexService) Do() (*DeleteIndexResult, error) {
  24. // Build url
  25. path, err := uritemplates.Expand("/{index}/", map[string]string{
  26. "index": b.index,
  27. })
  28. if err != nil {
  29. return nil, err
  30. }
  31. // Get response
  32. res, err := b.client.PerformRequest("DELETE", path, nil, nil)
  33. if err != nil {
  34. return nil, err
  35. }
  36. // Return result
  37. ret := new(DeleteIndexResult)
  38. if err := json.Unmarshal(res.Body, ret); err != nil {
  39. return nil, err
  40. }
  41. return ret, nil
  42. }
  43. // -- Result of a delete index request.
  44. type DeleteIndexResult struct {
  45. Acknowledged bool `json:"acknowledged"`
  46. }