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

Update index settings API
This commit is contained in:
Jérôme Renard 2015-10-11 08:07:22 +02:00
commit b44bb059a1
2 changed files with 36 additions and 6 deletions

22
goes.go
View File

@ -75,6 +75,20 @@ func (c *Connection) RefreshIndex(name string) (*Response, error) {
return r.Run() return r.Run()
} }
// UpdateIndexSettings updates settings for existing index represented by a name and a settings
// as described here: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
func (c *Connection) UpdateIndexSettings(name string, settings interface{}) (*Response, error) {
r := Request{
Conn: c,
Query: settings,
IndexList: []string{name},
method: "PUT",
api: "_settings",
}
return r.Run()
}
// Optimize an index represented by a name, extra args are also allowed please check: // 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 // 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) { func (c *Connection) Optimize(indexList []string, extraArgs url.Values) (*Response, error) {
@ -343,12 +357,10 @@ func (req *Request) Run() (*Response, error) {
if err != nil { if err != nil {
return esResp, err return esResp, err
} }
json.Unmarshal(body, &esResp.Raw) err = json.Unmarshal(body, &esResp.Raw)
}
err = json.Unmarshal(body, &esResp)
if err != nil { if err != nil {
return &Response{Status: statusCode}, err return esResp, err
}
} }
if req.api == "_bulk" && esResp.Errors { if req.api == "_bulk" && esResp.Errors {

View File

@ -180,6 +180,24 @@ func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) {
c.Assert(resp, DeepEquals, expectedResponse) c.Assert(resp, DeepEquals, expectedResponse)
} }
func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) {
conn := NewConnection(ES_HOST, ES_PORT)
indexName := "testupdateindex"
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
c.Assert(err, IsNil)
_, err = conn.UpdateIndexSettings(indexName, map[string]interface{}{
"index": map[string]interface{}{
"number_of_replicas": 0,
},
})
c.Assert(err, IsNil)
_, err = conn.DeleteIndex(indexName)
c.Assert(err, IsNil)
}
func (s *GoesTestSuite) TestRefreshIndex(c *C) { func (s *GoesTestSuite) TestRefreshIndex(c *C) {
conn := NewConnection(ES_HOST, ES_PORT) conn := NewConnection(ES_HOST, ES_PORT)
indexName := "testrefreshindex" indexName := "testrefreshindex"