From bf0b8b5bc89f258fb947b8c97ece77eece75662d Mon Sep 17 00:00:00 2001 From: r--w Date: Fri, 2 Oct 2015 13:25:29 +0200 Subject: [PATCH] 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"