RemoveAlias implementation, reusing code
This commit is contained in:
parent
13bf94fc2e
commit
f6ba59e55a
15
goes.go
15
goes.go
@ -529,15 +529,14 @@ func (c *Connection) DeleteMapping(typeName string, indexes []string) (Response,
|
||||
return r.Run()
|
||||
}
|
||||
|
||||
// AddAlias creates an alias to one or more indexes
|
||||
func (c *Connection) AddAlias(alias string, indexes []string) (Response, error) {
|
||||
func (c *Connection) modifyAlias(action string, alias string, indexes []string) (Response, error) {
|
||||
command := map[string]interface{}{
|
||||
"actions": make([]map[string]interface{}, 1),
|
||||
}
|
||||
|
||||
for _, index := range indexes {
|
||||
command["actions"] = append(command["actions"].([]map[string]interface{}), map[string]interface{}{
|
||||
"add": map[string]interface{}{
|
||||
action: map[string]interface{}{
|
||||
"index": index,
|
||||
"alias": alias,
|
||||
},
|
||||
@ -553,3 +552,13 @@ func (c *Connection) AddAlias(alias string, indexes []string) (Response, error)
|
||||
|
||||
return r.Run()
|
||||
}
|
||||
|
||||
// AddAlias creates an alias to one or more indexes
|
||||
func (c *Connection) AddAlias(alias string, indexes []string) (Response, error) {
|
||||
return c.modifyAlias("add", alias, indexes)
|
||||
}
|
||||
|
||||
// RemoveAlias removes an alias to one or more indexes
|
||||
func (c *Connection) RemoveAlias(alias string, indexes []string) (Response, error) {
|
||||
return c.modifyAlias("remove", alias, indexes)
|
||||
}
|
||||
|
41
goes_test.go
41
goes_test.go
@ -1321,3 +1321,44 @@ func (s *GoesTestSuite) TestAddAlias(c *C) {
|
||||
response.Raw = nil
|
||||
c.Assert(response, DeepEquals, expectedResponse)
|
||||
}
|
||||
|
||||
func (s *GoesTestSuite) TestRemoveAlias(c *C) {
|
||||
aliasName := "testAlias"
|
||||
indexName := "testalias_1"
|
||||
docType := "testDoc"
|
||||
docId := "1234"
|
||||
source := map[string]interface{}{
|
||||
"user": "foo",
|
||||
"message": "bar",
|
||||
}
|
||||
|
||||
conn := NewConnection(ES_HOST, ES_PORT)
|
||||
defer conn.DeleteIndex(indexName)
|
||||
|
||||
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
|
||||
c.Assert(err, IsNil)
|
||||
defer conn.DeleteIndex(indexName)
|
||||
|
||||
d := Document{
|
||||
Index: indexName,
|
||||
Type: docType,
|
||||
Id: docId,
|
||||
Fields: source,
|
||||
}
|
||||
|
||||
// Index data
|
||||
_, err = conn.Index(d, url.Values{})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// Add alias
|
||||
_, err = conn.AddAlias(aliasName, []string{indexName})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// Remove alias
|
||||
_, err = conn.RemoveAlias(aliasName, []string{indexName})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// Get document via alias
|
||||
_, err = conn.Get(aliasName, docType, docId, url.Values{})
|
||||
c.Assert(err.Error(), Equals, "[404] IndexMissingException[["+aliasName+"] missing]")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user