Merge 6d8c5d2699 into 6c9647b81c
				
					
				
			This commit is contained in:
		
						commit
						07e75d5ca0
					
				
							
								
								
									
										66
									
								
								goes.go
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								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
 | 
			
		||||
// URL arguments, for example, to control routing, ttl, version, op_type, etc.
 | 
			
		||||
func (c *Connection) Index(d Document, extraArgs url.Values) (*Response, error) {
 | 
			
		||||
	if parent, ok := d.Parent.(string); ok {
 | 
			
		||||
		extraArgs.Set("parent", parent)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	r := Request{
 | 
			
		||||
		Conn:      c,
 | 
			
		||||
		Query:     d.Fields,
 | 
			
		||||
@ -601,3 +605,65 @@ func (c *Connection) AliasExists(alias string) (bool, error) {
 | 
			
		||||
 | 
			
		||||
	return resp.Status == 200, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CloseIndex closes an index represented by a name
 | 
			
		||||
func (c *Connection) CloseIndex(name string) (*Response, error) {
 | 
			
		||||
	r := Request{
 | 
			
		||||
		Conn:      c,
 | 
			
		||||
		IndexList: []string{name},
 | 
			
		||||
		method:    "POST",
 | 
			
		||||
		api:       "_close",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Run()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// OpenIndex opens an index represented by a name
 | 
			
		||||
func (c *Connection) OpenIndex(name string) (*Response, error) {
 | 
			
		||||
	r := Request{
 | 
			
		||||
		Conn:      c,
 | 
			
		||||
		IndexList: []string{name},
 | 
			
		||||
		method:    "POST",
 | 
			
		||||
		api:       "_open",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Run()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Connection) GetAliases(indexes []string) (*Response, error) {
 | 
			
		||||
 | 
			
		||||
	r := Request{
 | 
			
		||||
		Conn:      c,
 | 
			
		||||
		IndexList: indexes,
 | 
			
		||||
		method:    "GET",
 | 
			
		||||
		api:       "_alias/",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Run()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Connection) ReplaceIndexInAlias(alias string, old_index string, new_index string) (*Response, error) {
 | 
			
		||||
	command := map[string]interface{}{
 | 
			
		||||
		"actions": make([]map[string]interface{}, 1),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	command["actions"] = append(command["actions"].([]map[string]interface{}), map[string]interface{}{
 | 
			
		||||
		"remove": map[string]interface{}{
 | 
			
		||||
			"index": old_index,
 | 
			
		||||
			"alias": alias,
 | 
			
		||||
		},
 | 
			
		||||
		"add": map[string]interface{}{
 | 
			
		||||
			"index": new_index,
 | 
			
		||||
			"alias": alias,
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	r := Request{
 | 
			
		||||
		Conn:   c,
 | 
			
		||||
		Query:  command,
 | 
			
		||||
		method: "POST",
 | 
			
		||||
		api:    "_aliases",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Run()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										56
									
								
								goes_test.go
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								goes_test.go
									
									
									
									
									
								
							@ -1424,3 +1424,59 @@ func (s *GoesTestSuite) TestAliasExists(c *C) {
 | 
			
		||||
	exists, err = conn.AliasExists(alias)
 | 
			
		||||
	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{}
 | 
			
		||||
	BulkCommand string
 | 
			
		||||
	Fields      interface{}
 | 
			
		||||
	Parent      interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Represents the "items" field in a _bulk response
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user