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.
 
 
 

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