DeleteMapping implementation

This commit is contained in:
Marin Bek 2014-11-24 16:41:35 -08:00
parent 6c041327be
commit 1d1ad4d447
2 changed files with 59 additions and 0 deletions

13
goes.go
View File

@ -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()
}

View File

@ -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)
}