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.0 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
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
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. "encoding/json"
  7. "net/http"
  8. "net/url"
  9. )
  10. // Client represents a connection to elasticsearch
  11. type Client struct {
  12. // The host to connect to
  13. Host *url.URL
  14. // Client is the http client used to make requests, allowing settings things
  15. // such as timeouts etc
  16. Client *http.Client
  17. // Detected version of ES
  18. version string
  19. }
  20. // Response holds an elasticsearch response
  21. type Response struct {
  22. Acknowledged bool
  23. Error string
  24. RawError json.RawMessage `json:"error"`
  25. Errors bool
  26. Status uint64
  27. Took uint64
  28. TimedOut bool `json:"timed_out"`
  29. Shards Shard `json:"_shards"`
  30. Hits Hits
  31. Index string `json:"_index"`
  32. ID string `json:"_id"`
  33. Type string `json:"_type"`
  34. Version int `json:"_version"`
  35. Found bool
  36. Count int
  37. // Used by the _stats API
  38. All All `json:"_all"`
  39. // Used by the _bulk API
  40. Items []map[string]Item `json:"items,omitempty"`
  41. // Used by the GET API
  42. Source map[string]interface{} `json:"_source"`
  43. Fields map[string]interface{} `json:"fields"`
  44. // Used by the _status API
  45. Indices map[string]IndexStatus
  46. // Scroll id for iteration
  47. ScrollID string `json:"_scroll_id"`
  48. Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
  49. Raw map[string]interface{}
  50. }
  51. // Aggregation holds the aggregation portion of an ES response
  52. type Aggregation map[string]interface{}
  53. // Bucket represents a bucket for aggregation
  54. type Bucket map[string]interface{}
  55. // Document holds a document to send to elasticsearch
  56. type Document struct {
  57. // XXX : interface as we can support nil values
  58. Index interface{}
  59. Type string
  60. ID interface{}
  61. BulkCommand string
  62. Fields interface{}
  63. }
  64. // Item holds an item from the "items" field in a _bulk response
  65. type Item struct {
  66. Type string `json:"_type"`
  67. ID string `json:"_id"`
  68. Index string `json:"_index"`
  69. Version int `json:"_version"`
  70. Error string `json:"error"`
  71. Status uint64 `json:"status"`
  72. }
  73. // All represents the "_all" field when calling the _stats API
  74. // This is minimal but this is what I only need
  75. type All struct {
  76. Indices map[string]StatIndex `json:"indices"`
  77. Primaries map[string]StatPrimary `json:"primaries"`
  78. }
  79. // StatIndex contains stats for a specific index
  80. type StatIndex struct {
  81. Primaries map[string]StatPrimary `json:"primaries"`
  82. }
  83. // StatPrimary contains stats for a primary index
  84. type StatPrimary struct {
  85. // primary/docs:
  86. Count int
  87. Deleted int
  88. }
  89. // Shard holds the "shard" struct as returned by elasticsearch
  90. type Shard struct {
  91. Total uint64
  92. Successful uint64
  93. Failed uint64
  94. }
  95. // Hit holds a hit returned by a search
  96. type Hit struct {
  97. Index string `json:"_index"`
  98. Type string `json:"_type"`
  99. ID string `json:"_id"`
  100. Score float64 `json:"_score"`
  101. Source map[string]interface{} `json:"_source"`
  102. Highlight map[string]interface{} `json:"highlight"`
  103. Fields map[string]interface{} `json:"fields"`
  104. }
  105. // Hits holds the hits structure as returned by elasticsearch
  106. type Hits struct {
  107. Total uint64
  108. // max_score may contain the "null" value
  109. MaxScore interface{} `json:"max_score"`
  110. Hits []Hit
  111. }
  112. // SearchError holds errors returned from an ES search
  113. type SearchError struct {
  114. Msg string
  115. StatusCode uint64
  116. }
  117. // IndexStatus holds the status for a given index for the _status command
  118. type IndexStatus struct {
  119. // XXX : problem, int will be marshaled to a float64 which seems logical
  120. // XXX : is it better to use strings even for int values or to keep
  121. // XXX : interfaces and deal with float64 ?
  122. Index map[string]interface{}
  123. Translog map[string]uint64
  124. Docs map[string]uint64
  125. Merges map[string]interface{}
  126. Refresh map[string]interface{}
  127. Flush map[string]interface{}
  128. // TODO: add shards support later, we do not need it for the moment
  129. }