Support for PutMapping API

This commit is contained in:
Marin Bek 2014-11-11 14:37:34 +01:00
parent 17253e07b0
commit f8e5a2a433
2 changed files with 56 additions and 0 deletions

14
goes.go
View File

@ -423,3 +423,17 @@ func (b Bucket) Aggregation(name string) Aggregation {
return Aggregation{}
}
}
// PutMapping registers a specific mapping for one or more types in one or more indexes
func (c *Connection) PutMapping(typeName string, mapping map[string]interface{}, indexes ...string) (Response, error) {
r := Request{
Conn: c,
Query: mapping,
IndexList: indexes,
method: "PUT",
api: "_mappings/" + typeName,
}
return r.Run()
}

View File

@ -970,3 +970,45 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
c.Assert(age["count"], Equals, 2.0)
c.Assert(age["sum"], Equals, 25.0+30.0)
}
func (s *GoesTestSuite) TestPutMapping(c *C) {
indexName := "testputmapping"
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, indexName)
c.Assert(err, IsNil)
c.Assert(response.Acknowledged, Equals, true)
c.Assert(response.TimedOut, Equals, false)
}