support for parent-child relationship
This commit is contained in:
parent
23413ed12a
commit
8413c690d4
4
goes.go
4
goes.go
@ -309,6 +309,10 @@ func (c *Connection) Get(index string, documentType string, id string, extraArgs
|
|||||||
// The extraArgs is a list of url.Values that you can send to elasticsearch as
|
// The extraArgs is a list of url.Values that you can send to elasticsearch as
|
||||||
// URL arguments, for example, to control routing, ttl, version, op_type, etc.
|
// URL arguments, for example, to control routing, ttl, version, op_type, etc.
|
||||||
func (c *Connection) Index(d Document, extraArgs url.Values) (*Response, error) {
|
func (c *Connection) Index(d Document, extraArgs url.Values) (*Response, error) {
|
||||||
|
if parent, ok := d.Parent.(string); ok {
|
||||||
|
extraArgs.Set("parent", parent)
|
||||||
|
}
|
||||||
|
|
||||||
r := Request{
|
r := Request{
|
||||||
Conn: c,
|
Conn: c,
|
||||||
Query: d.Fields,
|
Query: d.Fields,
|
||||||
|
56
goes_test.go
56
goes_test.go
@ -1424,3 +1424,59 @@ func (s *GoesTestSuite) TestAliasExists(c *C) {
|
|||||||
exists, err = conn.AliasExists(alias)
|
exists, err = conn.AliasExists(alias)
|
||||||
c.Assert(exists, Equals, true)
|
c.Assert(exists, Equals, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GoesTestSuite) TestIndexWithChild(c *C) {
|
||||||
|
indexName := "testindexwithchild"
|
||||||
|
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)
|
||||||
|
|
||||||
|
authorDoc := Document{
|
||||||
|
Index: indexName,
|
||||||
|
Type: "author",
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"name": "An Author",
|
||||||
|
},
|
||||||
|
Id: "aut",
|
||||||
|
}
|
||||||
|
response, err := conn.Index(authorDoc, 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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"_parent": map[string]interface{}{
|
||||||
|
"type": "author",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
response, err = conn.PutMapping("tweet", mapping, []string{indexName})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
c.Assert(response.Acknowledged, Equals, true)
|
||||||
|
c.Assert(response.TimedOut, Equals, false)
|
||||||
|
|
||||||
|
d := Document{
|
||||||
|
Index: indexName,
|
||||||
|
Type: docType,
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"count": 5,
|
||||||
|
},
|
||||||
|
Parent: "aut",
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err = conn.Index(d, url.Values{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
}
|
||||||
|
@ -107,6 +107,7 @@ type Document struct {
|
|||||||
Id interface{}
|
Id interface{}
|
||||||
BulkCommand string
|
BulkCommand string
|
||||||
Fields interface{}
|
Fields interface{}
|
||||||
|
Parent interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents the "items" field in a _bulk response
|
// Represents the "items" field in a _bulk response
|
||||||
|
Loading…
Reference in New Issue
Block a user