AliasExists implementation
This commit is contained in:
parent
aedb5f6b85
commit
5e4a4d663a
14
goes.go
14
goes.go
@ -562,3 +562,17 @@ func (c *Connection) AddAlias(alias string, indexes []string) (Response, error)
|
||||
func (c *Connection) RemoveAlias(alias string, indexes []string) (Response, error) {
|
||||
return c.modifyAlias("remove", alias, indexes)
|
||||
}
|
||||
|
||||
// AliasExists checks whether alias is defined on the server
|
||||
func (c *Connection) AliasExists(alias string) (bool, error) {
|
||||
|
||||
r := Request{
|
||||
Conn: c,
|
||||
method: "HEAD",
|
||||
api: "_alias/" + alias,
|
||||
}
|
||||
|
||||
resp, err := r.Run()
|
||||
|
||||
return resp.Status == 200, err
|
||||
}
|
||||
|
25
goes_test.go
25
goes_test.go
@ -1363,3 +1363,28 @@ func (s *GoesTestSuite) TestRemoveAlias(c *C) {
|
||||
_, err = conn.Get(aliasName, docType, docId, url.Values{})
|
||||
c.Assert(err.Error(), Equals, "[404] IndexMissingException[["+aliasName+"] missing]")
|
||||
}
|
||||
|
||||
func (s *GoesTestSuite) TestAliasExists(c *C) {
|
||||
index := "testaliasexist_1"
|
||||
alias := "testaliasexists"
|
||||
|
||||
conn := NewConnection(ES_HOST, ES_PORT)
|
||||
// just in case
|
||||
conn.DeleteIndex(index)
|
||||
|
||||
exists, err := conn.AliasExists(alias)
|
||||
c.Assert(exists, Equals, false)
|
||||
|
||||
_, err = conn.CreateIndex(index, map[string]interface{}{})
|
||||
c.Assert(err, IsNil)
|
||||
defer conn.DeleteIndex(index)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
_, err = conn.AddAlias(alias, []string{index})
|
||||
c.Assert(err, IsNil)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
defer conn.RemoveAlias(alias, []string{index})
|
||||
|
||||
exists, err = conn.AliasExists(alias)
|
||||
c.Assert(exists, Equals, true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user