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.

structs.go 4.2 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. Fields map[string]interface{} `json:"fields"`
  122. }
  123. // Represent the hits structure as returned by elasticsearch
  124. type Hits struct {
  125. Total uint64
  126. // max_score may contain the "null" value
  127. MaxScore interface{} `json:"max_score"`
  128. Hits []Hit
  129. }
  130. type SearchError struct {
  131. Msg string
  132. StatusCode uint64
  133. }
  134. // Represent the status for a given index for the _status command
  135. type IndexStatus struct {
  136. // XXX : problem, int will be marshaled to a float64 which seems logical
  137. // XXX : is it better to use strings even for int values or to keep
  138. // XXX : interfaces and deal with float64 ?
  139. Index map[string]interface{}
  140. Translog map[string]uint64
  141. Docs map[string]uint64
  142. Merges map[string]interface{}
  143. Refresh map[string]interface{}
  144. Flush map[string]interface{}
  145. // TODO: add shards support later, we do not need it for the moment
  146. }