Browse Source

AliasExists implementation

tags/v1.0.0
Marin Bek 9 years ago
parent
commit
5e4a4d663a
2 changed files with 39 additions and 0 deletions
  1. +14
    -0
      goes.go
  2. +25
    -0
      goes_test.go

+ 14
- 0
goes.go View File

@@ -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
- 0
goes_test.go View File

@@ -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…
Cancel
Save