Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions es.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ func (c *Client) GetIndices(index string) ([]Index, error) {
return indices, nil
}

// Get a subset of indices including hidden ones
func (c *Client) GetHiddenIndices(index string) ([]Index, error) {
Copy link
Copy Markdown
Contributor

@antkaynak antkaynak Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding - what does hidden indices mean here? Why are they hidden ( including ds-ilm-history indices ) 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some indices created by ILM itself. These indices keep metadata about ILM. Users can also create their own hidden indices by setting correct flag during index generation. This will prevent these indices to appear while listing indices without proper flag.

var indices []Index
err := handleErrWithStruct(c.buildGetRequest(fmt.Sprintf("_cat/indices/%s?h=health,status,index,pri,rep,store.size,docs.count&expand_wildcards=open,closed,hidden", index)), &indices)

if err != nil {
return nil, err
}

return indices, nil
}

// Get all the aliases in the cluster.
//
// Use case: You want to see some basic info on all the aliases of the cluster
Expand Down Expand Up @@ -1673,3 +1685,27 @@ func (c *Client) AllocateStalePrimaryShard(node, index string, shard int) error

return nil
}

// RemoveIndexILMPolicy removes the ILM policy from the index
func (c *Client) RemoveIndexILMPolicy(index string) error {
agent := c.buildPostRequest(fmt.Sprintf("%s/_ilm/remove", index))
Comment thread
UyumazHakan marked this conversation as resolved.

_, err := handleErrWithBytes(agent)
if err != nil {
return err
}

ilmHistoryIndices, err := c.GetHiddenIndices(fmt.Sprintf("%s*.ds-ilm-history-*", index))
if err != nil {
return err
}

for _, ilmHistoryIndex := range ilmHistoryIndices {
err = c.DeleteIndex(ilmHistoryIndex.Name)
if err != nil {
return err
}
}

return nil
}
21 changes: 21 additions & 0 deletions es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2212,3 +2212,24 @@ func TestAllocateStalePrimaryShard(t *testing.T) {
t.Fatalf("Unexpected error. expected nil, got %s", err)
}
}

func TestRemoveIndexILMPolicy(t *testing.T) {
ilmRemoveTestSetup := &ServerSetup{
Method: "POST",
Path: "/test-index/_ilm/remove",
}
getIndicesTestSetup := &ServerSetup{
Method: "GET",
Path: "/_cat/indices/test-index*.ds-ilm-history-*",
Response: "[]",
}

host, port, ts := setupTestServers(t, []*ServerSetup{ilmRemoveTestSetup, getIndicesTestSetup})
defer ts.Close()
client := NewClient(host, port)

err := client.RemoveIndexILMPolicy("test-index")
if err != nil {
t.Fatalf("Unexpected error. expected nil, got %s", err)
}
}