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.

преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. Ok bool
  41. Acknowledged bool
  42. Error string
  43. Status uint64
  44. Took uint64
  45. TimedOut bool `json:"timed_out"`
  46. Shards Shard `json:"_shards"`
  47. Hits Hits
  48. Index string `json:"_index"`
  49. Id string `json:"_id"`
  50. Type string `json:"_type"`
  51. Version int `json:"_version"`
  52. Found bool
  53. // Used by the _stats API
  54. All All `json:"_all"`
  55. // Used by the _bulk API
  56. Items []map[string]Item `json:"items,omitempty"`
  57. // Used by the GET API
  58. Exists bool
  59. Source map[string]interface{} `json:"_source"`
  60. Fields map[string]interface{} `json:"fields"`
  61. // Used by the _status API
  62. Indices map[string]IndexStatus
  63. // Scroll id for iteration
  64. ScrollId string `json:"_scroll_id"`
  65. }
  66. // Represents a document to send to elasticsearch
  67. type Document struct {
  68. // XXX : interface as we can support nil values
  69. Index interface{}
  70. Type string
  71. Id interface{}
  72. BulkCommand string
  73. Fields map[string]interface{}
  74. }
  75. // Represents the "items" field in a _bulk response
  76. type Item struct {
  77. Ok bool `json:"ok"`
  78. Type string `json:"_type"`
  79. Id string `json:"_id"`
  80. Index string `json:"_index"`
  81. Version int `json:"_version"`
  82. }
  83. // Represents the "_all" field when calling the _stats API
  84. // This is minimal but this is what I only need
  85. type All struct {
  86. Indices map[string]StatIndex `json:"indices"`
  87. Primaries map[string]StatPrimary `json:"primaries"`
  88. }
  89. type StatIndex struct {
  90. Primaries map[string]StatPrimary `json:"primaries"`
  91. }
  92. type StatPrimary struct {
  93. // primary/docs:
  94. Count int
  95. Deleted int
  96. }
  97. // Represents the "shard" struct as returned by elasticsearch
  98. type Shard struct {
  99. Total uint64
  100. Successful uint64
  101. Failed uint64
  102. }
  103. // Represent a hit returned by a search
  104. type Hit struct {
  105. Index string `json:"_index"`
  106. Type string `json:"_type"`
  107. Id string `json:"_id"`
  108. Score float64 `json:"_score"`
  109. Source map[string]interface{} `json:"_source"`
  110. Fields map[string]interface{} `json:"fields"`
  111. }
  112. // Represent the hits structure as returned by elasticsearch
  113. type Hits struct {
  114. Total uint64
  115. // max_score may contain the "null" value
  116. MaxScore interface{} `json:"max_score"`
  117. Hits []Hit
  118. }
  119. type SearchError struct {
  120. Msg string
  121. StatusCode uint64
  122. }
  123. // Represent the status for a given index for the _status command
  124. type IndexStatus struct {
  125. // XXX : problem, int will be marshaled to a float64 which seems logical
  126. // XXX : is it better to use strings even for int values or to keep
  127. // XXX : interfaces and deal with float64 ?
  128. Index map[string]interface{}
  129. Translog map[string]uint64
  130. Docs map[string]uint64
  131. Merges map[string]interface{}
  132. Refresh map[string]interface{}
  133. Flush map[string]interface{}
  134. // TODO: add shards support later, we do not need it for the moment
  135. }