GetMapping implementation

This commit is contained in:
Marin Bek 2014-11-13 09:22:11 +01:00
parent 589282a189
commit 08d26b69e0
2 changed files with 45 additions and 0 deletions

12
goes.go
View File

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

View File

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