我是Elastic搜索的新手,我已经编写了代码来索引City列表。我正在为Chrome使用“ elasticsearch head”插件,以检查和操作索引和_doc。
虽然正确生成了doc的索引和CRUD操作,但我不得不通过elastic-search插件手动删除索引。
我想先检查索引,如果有索引,将其删除,然后创建索引并再次索引城市列表。这就是我要做的。但是在Delete()方法中出错,说
参数1:无法从字符串转换为Nest.IDeleteRequest
以下是我的代码向您展示我在做什么:
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;
}
我已经搜索了弹性搜索文档,但是在NEST 7.4.1文档中找不到任何API,这会删除index本身。相反,我得到的是NEST版本1.x。
指向文档的任何链接或有关代码的任何帮助将非常有帮助。
谢谢。
公开负责从elasticsearch中删除文档的elasticsearch delete API。>>
如果要删除索引,可以使用此方法
await client.Indices.DeleteAsync("index_name");
希望有所帮助。