Support for PutMapping API
This commit is contained in:
parent
17253e07b0
commit
f8e5a2a433
14
goes.go
14
goes.go
@ -423,3 +423,17 @@ func (b Bucket) Aggregation(name string) Aggregation {
|
|||||||
return 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()
|
||||||
|
}
|
||||||
|
42
goes_test.go
42
goes_test.go
@ -970,3 +970,45 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
|
|||||||
c.Assert(age["count"], Equals, 2.0)
|
c.Assert(age["count"], Equals, 2.0)
|
||||||
c.Assert(age["sum"], Equals, 25.0+30.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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user