Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

159 řádky
4.0 KiB

  1. // Copyright 2013 Belogik. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package goes
  5. import (
  6. "encoding/json"
  7. "net/http"
  8. )
  9. // Client represents a connection to elasticsearch
  10. type Client struct {
  11. // The host to connect to
  12. Host string
  13. // The port to use
  14. Port string
  15. // Client is the http client used to make requests, allowing settings things
  16. // such as timeouts etc
  17. Client *http.Client
  18. // Detected version of ES
  19. version string
  20. }
  21. // Response holds an elasticsearch response
  22. type Response struct {
  23. Acknowledged bool
  24. Error string
  25. RawError json.RawMessage `json:"error"`
  26. Errors bool
  27. Status uint64
  28. Took uint64
  29. TimedOut bool `json:"timed_out"`
  30. Shards Shard `json:"_shards"`
  31. Hits Hits
  32. Index string `json:"_index"`
  33. ID string `json:"_id"`
  34. Type string `json:"_type"`
  35. Version int `json:"_version"`
  36. Found bool
  37. Count int
  38. // Used by the _stats API
  39. All All `json:"_all"`
  40. // Used by the _bulk API
  41. Items []map[string]Item `json:"items,omitempty"`
  42. // Used by the GET API
  43. Source map[string]interface{} `json:"_source"`
  44. Fields map[string]interface{} `json:"fields"`
  45. // Used by the _status API
  46. Indices map[string]IndexStatus
  47. // Scroll id for iteration
  48. ScrollID string `json:"_scroll_id"`
  49. Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
  50. Raw map[string]interface{}
  51. }
  52. // Aggregation holds the aggregation portion of an ES response
  53. type Aggregation map[string]interface{}
  54. // Bucket represents a bucket for aggregation
  55. type Bucket map[string]interface{}
  56. // Document holds a document to send to elasticsearch
  57. type Document struct {
  58. // XXX : interface as we can support nil values
  59. Index interface{}
  60. Type string
  61. ID interface{}
  62. BulkCommand string
  63. Fields interface{}
  64. }
  65. // Item holds an item from the "items" field in a _bulk response
  66. type Item struct {
  67. Type string `json:"_type"`
  68. ID string `json:"_id"`
  69. Index string `json:"_index"`
  70. Version int `json:"_version"`
  71. Error string `json:"error"`
  72. Status uint64 `json:"status"`
  73. }
  74. // All represents the "_all" field when calling the _stats API
  75. // This is minimal but this is what I only need
  76. type All struct {
  77. Indices map[string]StatIndex `json:"indices"`
  78. Primaries map[string]StatPrimary `json:"primaries"`
  79. }
  80. // StatIndex contains stats for a specific index
  81. type StatIndex struct {
  82. Primaries map[string]StatPrimary `json:"primaries"`
  83. }
  84. // StatPrimary contains stats for a primary index
  85. type StatPrimary struct {
  86. // primary/docs:
  87. Count int
  88. Deleted int
  89. }
  90. // Shard holds the "shard" struct as returned by elasticsearch
  91. type Shard struct {
  92. Total uint64
  93. Successful uint64
  94. Failed uint64
  95. }
  96. // Hit holds a hit returned by a search
  97. type Hit struct {
  98. Index string `json:"_index"`
  99. Type string `json:"_type"`
  100. ID string `json:"_id"`
  101. Score float64 `json:"_score"`
  102. Source map[string]interface{} `json:"_source"`
  103. Highlight map[string]interface{} `json:"highlight"`
  104. Fields map[string]interface{} `json:"fields"`
  105. }
  106. // Hits holds the hits structure as returned by elasticsearch
  107. type Hits struct {
  108. Total uint64
  109. // max_score may contain the "null" value
  110. MaxScore interface{} `json:"max_score"`
  111. Hits []Hit
  112. }
  113. // SearchError holds errors returned from an ES search
  114. type SearchError struct {
  115. Msg string
  116. StatusCode uint64
  117. }
  118. // IndexStatus holds the status for a given index for the _status command
  119. type IndexStatus struct {
  120. // XXX : problem, int will be marshaled to a float64 which seems logical
  121. // XXX : is it better to use strings even for int values or to keep
  122. // XXX : interfaces and deal with float64 ?
  123. Index map[string]interface{}
  124. Translog map[string]uint64
  125. Docs map[string]uint64
  126. Merges map[string]interface{}
  127. Refresh map[string]interface{}
  128. Flush map[string]interface{}
  129. // TODO: add shards support later, we do not need it for the moment
  130. }