Merge pull request #20 from r--w/master

Optimize API
This commit is contained in:
Jérôme Renard 2014-11-21 11:43:56 +01:00
commit 264c997862
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()
}
// 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
func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response, error) {
r := Request{

View File

@ -190,6 +190,26 @@ func (s *GoesTestSuite) TestRefreshIndex(c *C) {
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) {
indexName := "testbulkadd"
docType := "tweet"