From 08d26b69e0df37500f7c83ba0cc495c91530d30d Mon Sep 17 00:00:00 2001 From: Marin Bek Date: Thu, 13 Nov 2014 09:22:11 +0100 Subject: [PATCH] GetMapping implementation --- goes.go | 12 ++++++++++++ goes_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/goes.go b/goes.go index 84d171a..9216818 100644 --- a/goes.go +++ b/goes.go @@ -443,6 +443,18 @@ func (c *Connection) PutMapping(typeName string, mapping map[string]interface{}, return r.Run() } +func (c *Connection) GetMapping(types []string, indexes ...string) (Response, error) { + + r := Request{ + Conn: c, + IndexList: indexes, + method: "GET", + api: "_mapping/" + strings.Join(types, ","), + } + + return r.Run() +} + // IndicesExist checks whether index (or indices) exist on the server func (c *Connection) IndicesExist(indexes ...string) (bool, error) { diff --git a/goes_test.go b/goes_test.go index 9a33f27..21a88ff 100644 --- a/goes_test.go +++ b/goes_test.go @@ -1119,3 +1119,36 @@ func (s *GoesTestSuite) TestUpdate(c *C) { c.Assert(response.Source["user"], Equals, "admin") c.Assert(response.Source["message"], Equals, "candybar") } + +func (s *GoesTestSuite) TestGetMapping(c *C) { + indexName := "testmapping" + docType := "tweet" + + conn := NewConnection(ES_HOST, ES_PORT) + // just in case + conn.DeleteIndex(indexName) + + _, err := conn.CreateIndex(indexName, map[string]interface{}{}) + c.Assert(err, IsNil) + defer conn.DeleteIndex(indexName) + + response, err := conn.GetMapping([]string{docType}, indexName) + c.Assert(err, Equals, nil) + c.Assert(len(response.Raw), Equals, 0) + + d := Document{ + Index: indexName, + Type: docType, + Fields: map[string]interface{}{ + "user": "foo", + "message": "bar", + }, + } + + response, err = conn.Index(d, url.Values{}) + c.Assert(err, IsNil) + + response, err = conn.GetMapping([]string{docType}, indexName) + c.Assert(err, Equals, nil) + c.Assert(len(response.Raw), Not(Equals), 0) +}