Skip to content

Commit a2a3bc9

Browse files
Merge pull request #49 from jfrolich/delete-right-indices
Delete the right index
2 parents 921531e + 7ad220a commit a2a3bc9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/elasticsearch/indexing/index.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ defmodule Elasticsearch.Index do
5858
| {:error, Elasticsearch.Exception.t()}
5959
def starting_with(cluster, prefix) do
6060
with {:ok, indexes} <- Elasticsearch.get(cluster, "/_cat/indices?format=json") do
61-
prefix = to_string(prefix)
61+
prefix = prefix |> to_string() |> Regex.escape()
62+
{:ok, regex} = Regex.compile("^#{prefix}-[0-9]+$")
6263

6364
indexes =
6465
indexes
6566
|> Enum.map(& &1["index"])
66-
|> Enum.filter(&String.starts_with?(&1, prefix))
67+
|> Enum.filter(&Regex.match?(regex, &1))
6768
|> Enum.sort()
6869

6970
{:ok, indexes}

test/elasticsearch/indexing/index_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule Elasticsearch.IndexTest do
1616
{:ok,
1717
%HTTPoison.Response{
1818
status_code: 200,
19-
body: [%{"index" => "index-name"}]
19+
body: [%{"index" => "index-123"}]
2020
}}
2121
end
2222

0 commit comments

Comments
 (0)