问题
I'm new to Elastic search, using Elastic search version 7.7.1
I want to generate OAuth token by following Elastic Search documentation
When I've Tried below call through Kibana to get the OAuth token as per documentation:
POST /_security/oauth2/token
{
"grant_type" : "password",
"username" : "elastic",
"password" : "password_for_elastic_super_user"
}
then getting below Error:
{
"error" : {
"root_cause" : [
{
"type" : "invalid_index_name_exception",
"reason" : "Invalid index name [_security], must not start with '_', '-', or '+'",
"index_uuid" : "_na_",
"index" : "_security"
}
],
"type" : "invalid_index_name_exception",
"reason" : "Invalid index name [_security], must not start with '_', '-', or '+'",
"index_uuid" : "_na_",
"index" : "_security"
},
"status" : 400
}
Can anyone please help how to fix this?
回答1:
Elasticsearch creates the special index called .security-7
in version 7.X when x-pack security is enabled by setting xpack.security.enabled: true
and to access this index, you need to give _security
as index name when calling the security API like creating role, users etc
Below is one such example where I created the test
role when x-pack security is enabled.
endpoint http://{{hostname}}:{{port}}/_security/role/test // notice _security
{
"indices": [
{
"names": [
"ngram*"
],
"privileges": [
"all"
]
}
]
}
Note: In your case, it would not work unless x-pack-security is enabled and you can't create _security
index as its a special index which can be started with _
and is created by x-pack only.
来源:https://stackoverflow.com/questions/62592786/oauth-token-api-not-working-in-elastic-search-even-security-disabled