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.
 
 
 

185 lines
4.3 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. "net/http"
  7. "net/url"
  8. )
  9. // Represents a Connection object to elasticsearch
  10. type Connection 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. }
  19. // Represents a Request to elasticsearch
  20. type Request struct {
  21. // Which connection will be used
  22. Conn *Connection
  23. // A search query
  24. Query interface{}
  25. // Which index to search into
  26. IndexList []string
  27. // Which type to search into
  28. TypeList []string
  29. // HTTP Method to user (GET, POST ...)
  30. method string
  31. // Which api keyword (_search, _bulk, etc) to use
  32. api string
  33. // Bulk data
  34. bulkData []byte
  35. // Request body
  36. Body []byte
  37. // A list of extra URL arguments
  38. ExtraArgs url.Values
  39. // Used for the id field when indexing a document
  40. id string
  41. }
  42. // Represents a Response from elasticsearch
  43. type Response struct {
  44. Acknowledged bool
  45. Error string
  46. Errors bool
  47. Status uint64
  48. Took uint64
  49. TimedOut bool `json:"timed_out"`
  50. Shards Shard `json:"_shards"`
  51. Hits Hits
  52. Index string `json:"_index"`
  53. Id string `json:"_id"`
  54. Type string `json:"_type"`
  55. Version int `json:"_version"`
  56. Found bool
  57. Count int
  58. // Used by the _stats API
  59. All All `json:"_all"`
  60. // Used by the _bulk API
  61. Items []map[string]Item `json:"items,omitempty"`
  62. // Used by the GET API
  63. Source map[string]interface{} `json:"_source"`
  64. Fields map[string]interface{} `json:"fields"`
  65. // Used by the _status API
  66. Indices map[string]IndexStatus
  67. // Scroll id for iteration
  68. ScrollId string `json:"_scroll_id"`
  69. Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
  70. Raw map[string]interface{}
  71. }
  72. // Represents an aggregation from response
  73. type Aggregation map[string]interface{}
  74. // Represents a bucket for aggregation
  75. type Bucket map[string]interface{}
  76. // Represents a document to send to elasticsearch
  77. type Document struct {
  78. // XXX : interface as we can support nil values
  79. Index interface{}
  80. Type string
  81. Id interface{}
  82. BulkCommand string
  83. Fields interface{}
  84. }
  85. // Represents the "items" field in a _bulk response
  86. type Item struct {
  87. Type string `json:"_type"`
  88. Id string `json:"_id"`
  89. Index string `json:"_index"`
  90. Version int `json:"_version"`
  91. Error string `json:"error"`
  92. Status uint64 `json:"status"`
  93. }
  94. // Represents the "_all" field when calling the _stats API
  95. // This is minimal but this is what I only need
  96. type All struct {
  97. Indices map[string]StatIndex `json:"indices"`
  98. Primaries map[string]StatPrimary `json:"primaries"`
  99. }
  100. type StatIndex struct {
  101. Primaries map[string]StatPrimary `json:"primaries"`
  102. }
  103. type StatPrimary struct {
  104. // primary/docs:
  105. Count int
  106. Deleted int
  107. }
  108. // Represents the "shard" struct as returned by elasticsearch
  109. type Shard struct {
  110. Total uint64
  111. Successful uint64
  112. Failed uint64
  113. }
  114. // Represent a hit returned by a search
  115. type Hit struct {
  116. Index string `json:"_index"`
  117. Type string `json:"_type"`
  118. Id string `json:"_id"`
  119. Score float64 `json:"_score"`
  120. Source map[string]interface{} `json:"_source"`
  121. Highlight map[string]interface{} `json:"highlight"`
  122. Fields map[string]interface{} `json:"fields"`
  123. }
  124. // Represent the hits structure as returned by elasticsearch
  125. type Hits struct {
  126. Total uint64
  127. // max_score may contain the "null" value
  128. MaxScore interface{} `json:"max_score"`
  129. Hits []Hit
  130. }
  131. type SearchError struct {
  132. Msg string
  133. StatusCode uint64
  134. }
  135. // Represent the status for a given index for the _status command
  136. type IndexStatus struct {
  137. // XXX : problem, int will be marshaled to a float64 which seems logical
  138. // XXX : is it better to use strings even for int values or to keep
  139. // XXX : interfaces and deal with float64 ?
  140. Index map[string]interface{}
  141. Translog map[string]uint64
  142. Docs map[string]uint64
  143. Merges map[string]interface{}
  144. Refresh map[string]interface{}
  145. Flush map[string]interface{}
  146. // TODO: add shards support later, we do not need it for the moment
  147. }