diff --git a/goes.go b/goes.go index 8fae73c..a20de12 100644 --- a/goes.go +++ b/goes.go @@ -500,3 +500,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 e1db2db..49f3d5b 100644 --- a/goes_test.go +++ b/goes_test.go @@ -1180,3 +1180,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) +}