From 1d1ad4d447043f7ee793369d8af9c9032e5d99c4 Mon Sep 17 00:00:00 2001 From: Marin Bek Date: Mon, 24 Nov 2014 16:41:35 -0800 Subject: [PATCH] DeleteMapping implementation --- goes.go | 13 +++++++++++++ goes_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/goes.go b/goes.go index 6d737c4..2b791a5 100644 --- a/goes.go +++ b/goes.go @@ -486,3 +486,16 @@ func (c *Connection) Update(d Document, query map[string]interface{}, extraArgs return r.Run() } + +// DeleteMapping deletes a mapping along with all data in the type +func (c *Connection) DeleteMapping(typeName string, indexes []string) (Response, error) { + + r := Request{ + Conn: c, + IndexList: indexes, + method: "DELETE", + api: "_mappings/" + typeName, + } + + return r.Run() +} diff --git a/goes_test.go b/goes_test.go index ec3f492..e426c81 100644 --- a/goes_test.go +++ b/goes_test.go @@ -1160,3 +1160,49 @@ func (s *GoesTestSuite) TestGetMapping(c *C) { c.Assert(err, Equals, nil) c.Assert(len(response.Raw), Not(Equals), 0) } + +func (s *GoesTestSuite) TestDeleteMapping(c *C) { + indexName := "testdeletemapping" + 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) + + 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) + + mapping := map[string]interface{}{ + "tweet": map[string]interface{}{ + "properties": map[string]interface{}{ + "count": map[string]interface{}{ + "type": "integer", + "index": "not_analyzed", + "store": true, + }, + }, + }, + } + response, err = conn.PutMapping("tweet", mapping, []string{indexName}) + c.Assert(err, IsNil) + time.Sleep(200 * time.Millisecond) + + response, err = conn.DeleteMapping("tweet", []string{indexName}) + c.Assert(err, IsNil) + + c.Assert(response.Acknowledged, Equals, true) + c.Assert(response.TimedOut, Equals, false) +}