Skip to content

Commit

Permalink
Added features API
Browse files Browse the repository at this point in the history
  • Loading branch information
GRoguelon committed May 9, 2024
1 parent cf6b49c commit 134572e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
68 changes: 68 additions & 0 deletions lib/elasticsearch_ex/api/features.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
defmodule ElasticsearchEx.Api.Features do
@moduledoc """
You can use the following APIs to introspect and manage Features provided by Elasticsearch and
Elasticsearch plugins.
"""

alias ElasticsearchEx.Client

## Typespecs

@type opts :: ElasticsearchEx.opts()

## Public functions

@doc """
Gets a list of features which can be included in snapshots using the [`feature_states` field](https://www.elastic.co/guide/en/elasticsearch/reference/current/create-snapshot-api.html#create-snapshot-api-feature-states) when creating a snapshot.
### Examples
iex> ElasticsearchEx.Api.Features.get()
{:ok,
%{
"features" => [
%{
"description" => "Manages Kibana configuration and reports",
"name" => "kibana"
},
%{"description" => "Manages synonyms", "name" => "synonyms"}
]
}}
"""
@doc since: "1.5.0"
@spec get(opts()) :: ElasticsearchEx.response()
def get(opts \\ []) do
Client.get("_features", nil, nil, opts)
end

@doc """
Clears all of the state information stored in system indices by Elasticsearch features, including
the security and machine learning indices.
> #### Important {: .warning}
>
> Intended for development and testing use only. Do not reset features on a production cluster.
### Examples
iex> ElasticsearchEx.Api.Features.reset()
{:ok,
%{
"features" => [
%{
"feature_name" => "security",
"status" => "SUCCESS"
},
%{
"feature_name" => "tasks",
"status" => "SUCCESS"
}
]
}}
"""
@doc since: "1.5.0"
@spec reset(opts()) :: ElasticsearchEx.response()
def reset(opts \\ []) do
Client.post("_features/_reset", nil, nil, opts)
end
end
31 changes: 31 additions & 0 deletions test/elasticsearch_ex/api/features_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule ElasticsearchEx.Api.FeaturesTest do
use ElasticsearchEx.ConnCase

alias ElasticsearchEx.Api.Features

## Tests

describe "get/1" do
test "returns a successful response" do
assert {:ok, response} = Features.get()
assert is_map(response)
assert is_map_key(response, "features")
Enum.map(response["features"], fn feature ->
assert is_map_key(feature, "description")
assert is_map_key(feature, "name")
end)
end
end

describe "reset/1" do
test "returns a successful response" do
assert {:ok, response} = Features.reset()
assert is_map(response)
assert is_map_key(response, "features")
Enum.map(response["features"], fn feature ->
assert is_map_key(feature, "feature_name")
assert is_map_key(feature, "status")
end)
end
end
end

0 comments on commit 134572e

Please sign in to comment.