Added indexList and extraArgs support to Connection.Stats()

This commit is contained in:
Jérôme Renard 2013-06-18 08:04:52 +02:00
parent 92081c6d25
commit 726e1e80b9
2 changed files with 9 additions and 6 deletions

View File

@ -69,9 +69,11 @@ func (c *Connection) RefreshIndex(name string) (Response, error) {
} }
// Stats fetches statistics (_stats) for the current elasticsearch server // Stats fetches statistics (_stats) for the current elasticsearch server
func (c *Connection) Stats() (Response, error) { func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
IndexList: indexList,
ExtraArgs: extraArgs,
method: "GET", method: "GET",
api: "_stats", api: "_stats",
} }

View File

@ -292,15 +292,16 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {
func (s *GoesTestSuite) TestStats(c *C) { func (s *GoesTestSuite) TestStats(c *C) {
conn := NewConnection(ES_HOST, ES_PORT) conn := NewConnection(ES_HOST, ES_PORT)
indexName := "testfetchstats" indexName := "teststats"
conn.DeleteIndex(indexName)
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
c.Assert(err, IsNil) c.Assert(err, IsNil)
// we must wait for a bit otherwise ES crashes // we must wait for a bit otherwise ES crashes
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
response, err := conn.Stats() response, err := conn.Stats([]string{indexName}, url.Values{})
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(response.All.Indices[indexName].Primaries["docs"].Count, Equals, 0) c.Assert(response.All.Indices[indexName].Primaries["docs"].Count, Equals, 0)