Merge pull request #21 from marinbek/master
DeleteMapping implementation
This commit is contained in:
commit
cc93e7ac2c
13
goes.go
13
goes.go
@ -500,3 +500,16 @@ func (c *Connection) Update(d Document, query map[string]interface{}, extraArgs
|
|||||||
|
|
||||||
return r.Run()
|
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()
|
||||||
|
}
|
||||||
|
46
goes_test.go
46
goes_test.go
@ -1180,3 +1180,49 @@ func (s *GoesTestSuite) TestGetMapping(c *C) {
|
|||||||
c.Assert(err, Equals, nil)
|
c.Assert(err, Equals, nil)
|
||||||
c.Assert(len(response.Raw), Not(Equals), 0)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user