GetMapping implementation
This commit is contained in:
parent
589282a189
commit
08d26b69e0
12
goes.go
12
goes.go
@ -443,6 +443,18 @@ func (c *Connection) PutMapping(typeName string, mapping map[string]interface{},
|
|||||||
return r.Run()
|
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
|
// IndicesExist checks whether index (or indices) exist on the server
|
||||||
func (c *Connection) IndicesExist(indexes ...string) (bool, error) {
|
func (c *Connection) IndicesExist(indexes ...string) (bool, error) {
|
||||||
|
|
||||||
|
33
goes_test.go
33
goes_test.go
@ -1119,3 +1119,36 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
|
|||||||
c.Assert(response.Source["user"], Equals, "admin")
|
c.Assert(response.Source["user"], Equals, "admin")
|
||||||
c.Assert(response.Source["message"], Equals, "candybar")
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user