IndexExistsAsync in NEST 6.0

Hi,
I am new to Elastic search, and was trying to check an Index before creating a new one.
I am able to check it through IndexExists method but not by IndexExistsAsync. I have followed some of articles here in Elastic forum, but still unable to implement IndexExistsAsync method.

Please Help.

You want to check the list of indices before creating a newly named index to ensure no collision?

You will need to utilised the _cat api such as here: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/cat-indices.html

Yes, this is a way.. but I want to check the index via code, using NEST.
In NEST there are 2 methods,

  1. IndexExists - I am able to get result using this
  2. IndexExistsAsync - It's not working. I guess I am wrong in implementing it

for sure, can you share the code you are using ?

`public async Task ElasticIndexCheck(string indexName, ElasticClient client)
{
var req = new IndexExistsRequest(indexName);
IExistsResponse response = await client.IndexExistsAsync(req);

        return response;            
    }`

It's

var client = new ElasticClient();
var existsResponse = await client.IndexExistsAsync("index_name");

if (existsResponse.Exists)
{
    Console.WriteLine("It exists");
}

Sorry for my late response. But yes, it worked,, Thanks a lot :slight_smile:

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.