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.
 
 
 

143 lines
3.1 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. // A list of extra URL arguments
  32. ExtraArgs url.Values
  33. // Used for the id field when indexing a document
  34. id string
  35. }
  36. // Represents a search Response from elasticsearch
  37. type Response struct {
  38. Ok bool
  39. Acknowledged bool
  40. Error string
  41. Status uint64
  42. Took uint64
  43. TimedOut bool `json:"timed_out"`
  44. Shards Shard `json:"_shards"`
  45. Hits Hits
  46. Index string `json:"_index"`
  47. Id string `json:"_id"`
  48. Type string `json:"_type"`
  49. Version int `json:"_version"`
  50. Found bool
  51. // Used by the _stats API
  52. All All `json:"_all"`
  53. // Used by the _bulk API
  54. Items []map[string]Item `json:"items,omitempty"`
  55. // Used by the GET API
  56. Exists bool
  57. Source map[string]interface{} `json:"_source"`
  58. Fields map[string]interface{} `json:"fields"`
  59. }
  60. // Represents a document to send to elasticsearch
  61. type Document struct {
  62. // XXX : interface as we can support nil values
  63. Index interface{}
  64. Type string
  65. Id interface{}
  66. BulkCommand string
  67. Fields map[string]interface{}
  68. }
  69. // Represents the "items" field in a _bulk response
  70. type Item struct {
  71. Ok bool `json:"ok"`
  72. Type string `json:"_type"`
  73. Id string `json:"_id"`
  74. Index string `json:"_index"`
  75. Version int `json:"_version"`
  76. }
  77. // Represents the "_all" field when calling the _stats API
  78. // This is minimal but this is what I only need
  79. type All struct {
  80. Indices map[string]StatIndex `json:"indices"`
  81. Primaries map[string]StatPrimary `json:"primaries"`
  82. }
  83. type StatIndex struct {
  84. Primaries map[string]StatPrimary `json:"primaries"`
  85. }
  86. type StatPrimary struct {
  87. // primary/docs:
  88. Count int
  89. Deleted int
  90. }
  91. // Represents the "shard" struct as returned by elasticsearch
  92. type Shard struct {
  93. Total uint64
  94. Successful uint64
  95. Failed uint64
  96. }
  97. // Represent a hit returned by a search
  98. type Hit struct {
  99. Index string `json:"_index"`
  100. Type string `json:"_type"`
  101. Id string `json:"_id"`
  102. Score float64 `json:"_score"`
  103. Source map[string]interface{} `json:"_source"`
  104. Fields map[string]interface{} `json:"fields"`
  105. }
  106. // Represent the hits structure as returned by elasticsearch
  107. type Hits struct {
  108. Total uint64
  109. // max_score may contain the "null" value
  110. MaxScore interface{} `json:"max_score"`
  111. Hits []Hit
  112. }
  113. type SearchError struct {
  114. Msg string
  115. StatusCode uint64
  116. }