Added IndexStatus()

This commit is contained in:
Jérôme Renard 2013-06-23 08:59:23 +02:00
parent d01836c651
commit f7b8fcf842
3 changed files with 103 additions and 0 deletions

13
goes.go
View File

@ -81,6 +81,19 @@ func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response,
return r.Run() return r.Run()
} }
// IndexStatus fetches the status (_status) for the indices defined in
// indexList. Use _all in indexList to get stats for all indices
func (c *Connection) IndexStatus(indexList []string) (Response, error) {
r := Request{
Conn: c,
IndexList: indexList,
method: "GET",
api: "_status",
}
return r.Run()
}
// Bulk adds multiple documents in bulk mode to the index for a given type // Bulk adds multiple documents in bulk mode to the index for a given type
func (c *Connection) BulkSend(index string, documents []Document) (Response, error) { func (c *Connection) BulkSend(index string, documents []Document) (Response, error) {
// We do not generate a traditionnal JSON here (often a one liner) // We do not generate a traditionnal JSON here (often a one liner)

View File

@ -552,3 +552,74 @@ func (s *GoesTestSuite) TestSearch(c *C) {
c.Assert(response.Hits, DeepEquals, expectedHits) c.Assert(response.Hits, DeepEquals, expectedHits)
} }
func (s *GoesTestSuite) TestIndexStatus(c *C) {
indexName := "testindexstatus"
conn := NewConnection(ES_HOST, ES_PORT)
conn.DeleteIndex(indexName)
mapping := map[string]interface{}{
"settings": map[string]interface{}{
"index.number_of_shards": 1,
"index.number_of_replicas": 1,
},
}
_, err := conn.CreateIndex(indexName, mapping)
c.Assert(err, IsNil)
defer conn.DeleteIndex(indexName)
// gives ES some time to do its job
time.Sleep(1 * time.Second)
response, err := conn.IndexStatus([]string{"_all"})
c.Assert(err, IsNil)
c.Assert(response.Ok, Equals, true)
expectedShards := Shard{Total: 2, Successful: 1, Failed: 0}
c.Assert(response.Shards, Equals, expectedShards)
expectedIndices := map[string]IndexStatus{
indexName: IndexStatus{
Index: map[string]interface{}{
"primary_size": "99b",
"primary_size_in_bytes": float64(99),
"size": "99b",
"size_in_bytes": float64(99),
},
Translog: map[string]uint64{
"operations": 0,
},
Docs: map[string]uint64{
"num_docs": 0,
"max_doc": 0,
"deleted_docs": 0,
},
Merges: map[string]interface{}{
"current": float64(0),
"current_docs": float64(0),
"current_size": "0b",
"current_size_in_bytes": float64(0),
"total": float64(0),
"total_time": "0s",
"total_time_in_millis": float64(0),
"total_docs": float64(0),
"total_size": "0b",
"total_size_in_bytes": float64(0),
},
Refresh: map[string]interface{}{
"total": float64(1),
"total_time": "0s",
"total_time_in_millis": float64(0),
},
Flush: map[string]interface{}{
"total": float64(0),
"total_time": "0s",
"total_time_in_millis": float64(0),
},
},
}
c.Assert(response.Indices, DeepEquals, expectedIndices)
}

View File

@ -73,6 +73,9 @@ type Response struct {
Exists bool Exists bool
Source map[string]interface{} `json:"_source"` Source map[string]interface{} `json:"_source"`
Fields map[string]interface{} `json:"fields"` Fields map[string]interface{} `json:"fields"`
// Used by the _status API
Indices map[string]IndexStatus
} }
// Represents a document to send to elasticsearch // Represents a document to send to elasticsearch
@ -140,3 +143,19 @@ type SearchError struct {
Msg string Msg string
StatusCode uint64 StatusCode uint64
} }
// Represent the status for a given index for the _status command
type IndexStatus struct {
// XXX : problem, int will be marshaled to a float64 which seems logical
// XXX : is it better to use strings even for int values or to keep
// XXX : interfaces and deal with float64 ?
Index map[string]interface{}
Translog map[string]uint64
Docs map[string]uint64
Merges map[string]interface{}
Refresh map[string]interface{}
Flush map[string]interface{}
// TODO: add shards support later, we do not need it for the moment
}