How to connect to Elasticsearch from a .NET app using api key

22 Views Asked by At

Trying to work with Elasticsearch using a .NET app. Firstly, we generated an api key for access:

POST /_security/api_key
{
  "name": "ea-dev-auditlogs-api-key",
  "role_descriptors": { 
    "role-a": {
      "cluster": ["all"]
    }
    }
}

Then, we used the returned api key in our .NET app:

   string hosturl = "https://some-cluster.es.privatelink.eastus.azure.elastic-cloud.com:9243";
    string ApiAuthenticationId = "Nw-2-40BHA5_cCUUty";
    string ApiAuthenticationKey = "hYdmJ4_8SW2gXO3hhstdDQ";

The, we are trying to connect and read some indices:

var client = new ElasticClient(settings);
        var result = client.Cat.Indices();

What we get in return is this:

"Status code 403 from: GET /_cat/indices. ServerError: Type: security_exception Reason: "action [indices:monitor/settings/get] is unauthorized for API key id"

Granted, we have not created any ES indices just yet. We are trying to have a living of the available indices. When we run this commend from the Cabana dev console:

GET /_cat/indices

we do get the listing of internal indices beginning with "." We expect to have at least the same output from running the .NET code above.

What part do you thing we are missing?

0

There are 0 best solutions below