From bf0b8b5bc89f258fb947b8c97ece77eece75662d Mon Sep 17 00:00:00 2001 From: r--w Date: Fri, 2 Oct 2015 13:25:29 +0200 Subject: [PATCH 1/4] Update index settings API - https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html#indices-update-settings --- goes.go | 14 ++++++++++++++ goes_test.go | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/goes.go b/goes.go index 51e0fb1..6f16b0e 100644 --- a/goes.go +++ b/goes.go @@ -75,6 +75,20 @@ func (c *Connection) RefreshIndex(name string) (*Response, error) { 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 map[string]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: // 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) { diff --git a/goes_test.go b/goes_test.go index 69c9284..89bad3e 100644 --- a/goes_test.go +++ b/goes_test.go @@ -180,6 +180,24 @@ func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) { 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) { conn := NewConnection(ES_HOST, ES_PORT) indexName := "testrefreshindex" From 8fa9ff1c5354dd789f47c2381a7bef6cf82e92e6 Mon Sep 17 00:00:00 2001 From: r--w Date: Fri, 2 Oct 2015 13:59:55 +0200 Subject: [PATCH 2/4] Update index settings API --- goes.go | 2 +- goes_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/goes.go b/goes.go index 6f16b0e..f15000f 100644 --- a/goes.go +++ b/goes.go @@ -77,7 +77,7 @@ func (c *Connection) RefreshIndex(name string) (*Response, error) { // 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 map[string]interface{}) (Response, error) { +func (c *Connection) UpdateIndexSettings(name string, settings interface{}) (*Response, error) { r := Request{ Conn: c, Query: settings, diff --git a/goes_test.go b/goes_test.go index 89bad3e..fab8df7 100644 --- a/goes_test.go +++ b/goes_test.go @@ -187,7 +187,7 @@ func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) { _, err := conn.CreateIndex(indexName, map[string]interface{}{}) c.Assert(err, IsNil) - _, err := conn.UpdateIndexSettings(indexName, map[string]interface{}{ + _, err = conn.UpdateIndexSettings(indexName, map[string]interface{}{ "index": map[string]interface{}{ "number_of_replicas": 0, }, From aa49572462247f898c7f6244f6be0ca4a058f88a Mon Sep 17 00:00:00 2001 From: r--w Date: Fri, 2 Oct 2015 14:20:57 +0200 Subject: [PATCH 3/4] Fixing IndicesExist function --- goes.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/goes.go b/goes.go index f15000f..3781cff 100644 --- a/goes.go +++ b/goes.go @@ -358,11 +358,9 @@ func (req *Request) Run() (*Response, error) { return esResp, err } json.Unmarshal(body, &esResp.Raw) - } - - err = json.Unmarshal(body, &esResp) - if err != nil { - return &Response{Status: statusCode}, err + if err != nil { + return &Response{Status: statusCode}, err + } } if req.api == "_bulk" && esResp.Errors { From ae25be9f6f66548e67dc22ecea65063b3bbba6dc Mon Sep 17 00:00:00 2001 From: r--w Date: Fri, 2 Oct 2015 14:27:17 +0200 Subject: [PATCH 4/4] Fixing IndicesExist function --- goes.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/goes.go b/goes.go index 3781cff..84b43f3 100644 --- a/goes.go +++ b/goes.go @@ -357,10 +357,10 @@ func (req *Request) Run() (*Response, error) { if err != nil { return esResp, err } - json.Unmarshal(body, &esResp.Raw) - if err != nil { - return &Response{Status: statusCode}, err - } + err = json.Unmarshal(body, &esResp.Raw) + if err != nil { + return esResp, err + } } if req.api == "_bulk" && esResp.Errors {