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.
 
 
 

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