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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. // Used by the _stats API
  58. All All `json:"_all"`
  59. // Used by the _bulk API
  60. Items []map[string]Item `json:"items,omitempty"`
  61. // Used by the GET API
  62. Source map[string]interface{} `json:"_source"`
  63. Fields map[string]interface{} `json:"fields"`
  64. // Used by the _status API
  65. Indices map[string]IndexStatus
  66. // Scroll id for iteration
  67. ScrollId string `json:"_scroll_id"`
  68. Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
  69. Raw map[string]interface{}
  70. }
  71. // Represents an aggregation from response
  72. type Aggregation map[string]interface{}
  73. // Represents a bucket for aggregation
  74. type Bucket map[string]interface{}
  75. // Represents a document to send to elasticsearch
  76. type Document struct {
  77. // XXX : interface as we can support nil values
  78. Index interface{}
  79. Type string
  80. Id interface{}
  81. BulkCommand string
  82. Fields interface{}
  83. }
  84. // Represents the "items" field in a _bulk response
  85. type Item struct {
  86. Type string `json:"_type"`
  87. Id string `json:"_id"`
  88. Index string `json:"_index"`
  89. Version int `json:"_version"`
  90. Error string `json:"error"`
  91. Status uint64 `json:"status"`
  92. }
  93. // Represents the "_all" field when calling the _stats API
  94. // This is minimal but this is what I only need
  95. type All struct {
  96. Indices map[string]StatIndex `json:"indices"`
  97. Primaries map[string]StatPrimary `json:"primaries"`
  98. }
  99. type StatIndex struct {
  100. Primaries map[string]StatPrimary `json:"primaries"`
  101. }
  102. type StatPrimary struct {
  103. // primary/docs:
  104. Count int
  105. Deleted int
  106. }
  107. // Represents the "shard" struct as returned by elasticsearch
  108. type Shard struct {
  109. Total uint64
  110. Successful uint64
  111. Failed uint64
  112. }
  113. // Represent a hit returned by a search
  114. type Hit struct {
  115. Index string `json:"_index"`
  116. Type string `json:"_type"`
  117. Id string `json:"_id"`
  118. Score float64 `json:"_score"`
  119. Source map[string]interface{} `json:"_source"`
  120. Fields map[string]interface{} `json:"fields"`
  121. }
  122. // Represent the hits structure as returned by elasticsearch
  123. type Hits struct {
  124. Total uint64
  125. // max_score may contain the "null" value
  126. MaxScore interface{} `json:"max_score"`
  127. Hits []Hit
  128. }
  129. type SearchError struct {
  130. Msg string
  131. StatusCode uint64
  132. }
  133. // Represent the status for a given index for the _status command
  134. type IndexStatus struct {
  135. // XXX : problem, int will be marshaled to a float64 which seems logical
  136. // XXX : is it better to use strings even for int values or to keep
  137. // XXX : interfaces and deal with float64 ?
  138. Index map[string]interface{}
  139. Translog map[string]uint64
  140. Docs map[string]uint64
  141. Merges map[string]interface{}
  142. Refresh map[string]interface{}
  143. Flush map[string]interface{}
  144. // TODO: add shards support later, we do not need it for the moment
  145. }