I am new to Elastic search and I have written code to index a list of City. I am using "elasticsearch head" add-on for chrome to check and manipulate the indexes and _doc.
While indexing and CRUD operation of doc is resulting correctly, I had to delete the index manually via elastic-search add-on.
I want to check for the index first, if an index is available, delete it, and create the index & index the list of City again. This is what I want to do. But getting an error in Delete() method saying
argument 1: cannot convert from string to Nest.IDeleteRequest
Following is my code to show you what I am doing:
public async Task<List<BulkResponseItemBase>> AddNewIndex(string index_name, List<City> model)
{
client = new ElasticClient(elstcstngs);
List<BulkResponseItemBase> elstcManyrespoStatusList = new List<BulkResponseItemBase>();
if (await CheckIndexExists(index_name))
{
//This is where I am getting error - Cannot Convert from string to Nest.IDeleteRequest
client.Delete(index_name);
}
elstcstngs.DefaultMappingFor<City>(m => m.IndexName(index_name));
BulkResponse elstcManyrespoStatus = await client.IndexManyAsync<City>(model, null);
if (elstcManyrespoStatus.Errors)
{
foreach (var itemWithError in elstcManyrespoStatus.ItemsWithErrors)
{
elstcManyrespoStatusList.Add(itemWithError);
System.Diagnostics.Debug.WriteLine("Failed to index document {0}: {1}", itemWithError.Id, itemWithError.Error);
}
}
return elstcManyrespoStatusList;
}
I have searched the Elastic search Documentation but could not find any API in NEST 7.4.1 documentation, which will delete the index itself. Instead what I am getting is of NEST version 1.x.
Any link towards a documentation or any help regarding the code will very helpful.
Thank you.
As you can see from client.Delete
method description
it exposes elasticsearch delete API which is responsible for deleting documents from elasticsearch.
If you want to remove index you can do this with
await client.Indices.DeleteAsync("index_name");
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With