Browse Source

Optimize API

Optimize API added:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/in
dices-optimize.html#indices-optimize
tags/v1.0.0
r--w 9 years ago
parent
commit
6b8090a19d
2 changed files with 34 additions and 0 deletions
  1. +14
    -0
      goes.go
  2. +20
    -0
      goes_test.go

+ 14
- 0
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{


+ 20
- 0
goes_test.go 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"


Loading…
Cancel
Save