-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |