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.
client.Delete
method does not accept index name as parameter. It requires DeleteRequest object. That's what the error says. Or you need to use DeleteIndex method. elastic.co/guide/en/elasticsearch/client/net-api/1.x/… – Johanna.Delete(indexname)
, but rather with.Delete(new DeleteRequest(…))
. Which implementations ofIDeleteRequest
do exist? Can you instantiate one of them and parametrize them with the index name? – NephewDelete()
InsideIndices
property. Feeling dumb, why I could not get it earlier. – Catechol