Skip to content
Advertisement

Check if the index exists or not Elasticsearch

I want to check in elasticsearch if the index exists or not. If it not exists it should create the index and do other functionality. I try to find out a solution for that, but did not find any perfect solution for that. Can anyone have any solution to solve this problem.

I am using Elasticsearch library.

**$client = new ElasticsearchClient();**

Advertisement

Answer

As per index operations and source code the following should work

 $client = new ElasticsearchClient();
 $indexParams['index']  = 'my_index';   
 $client->indices()->exists($indexParams);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement