Optimize API

Optimize API added:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/in
dices-optimize.html#indices-optimize
This commit is contained in:
r--w 2014-11-21 11:06:24 +01:00
parent 63cef24bc9
commit 6b8090a19d
2 changed files with 34 additions and 0 deletions

14
goes.go
View File

@ -75,6 +75,20 @@ func (c *Connection) RefreshIndex(name string) (Response, error) {
return r.Run() return r.Run()
} }
// Optimize an index represented by a name, extra args are also allowed please check:
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-optimize.html#indices-optimize
func (c *Connection) Optimize(indexList []string, extraArgs url.Values) (Response, error) {
r := Request{
Conn: c,
IndexList: indexList,
ExtraArgs: extraArgs,
method: "POST",
api: "_optimize",
}
return r.Run()
}
// Stats fetches statistics (_stats) for the current elasticsearch server // Stats fetches statistics (_stats) for the current elasticsearch server
func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response, error) { func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response, error) {
r := Request{ r := Request{

View File

@ -190,6 +190,26 @@ func (s *GoesTestSuite) TestRefreshIndex(c *C) {
c.Assert(err, IsNil) c.Assert(err, IsNil)
} }
func (s *GoesTestSuite) TestOptimize(c *C) {
conn := NewConnection(ES_HOST, ES_PORT)
indexName := "testoptimize"
conn.DeleteIndex(indexName)
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
c.Assert(err, IsNil)
// we must wait for a bit otherwise ES crashes
time.Sleep(1 * time.Second)
response, err := conn.Optimize([]string{indexName}, url.Values{"max_num_segments" : []string{"1"}})
c.Assert(err, IsNil)
c.Assert(response.All.Indices[indexName].Primaries["docs"].Count, Equals, 0)
_, err = conn.DeleteIndex(indexName)
c.Assert(err, IsNil)
}
func (s *GoesTestSuite) TestBulkSend(c *C) { func (s *GoesTestSuite) TestBulkSend(c *C) {
indexName := "testbulkadd" indexName := "testbulkadd"
docType := "tweet" docType := "tweet"