IndexExistsAsync in NEST 6.0


(Arpan Sahoo) #1

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.


(Jymit Singh Khondhu) #2

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


(Arpan Sahoo) #3

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

(Jymit Singh Khondhu) #4

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


(Arpan Sahoo) #5

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

        return response;            
    }`

(Russ Cam) #6

It's

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

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

(Arpan Sahoo) #7

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


(system) #8

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