Ash*_*ope 6 c# elasticsearch nest
我是弹性搜索的新手,我编写了代码来索引城市列表。我正在使用 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;
}
Run Code Online (Sandbox Code Playgroud)
我搜索了 Elastic 搜索文档,但在 NEST 7.4.1 文档中找不到任何 API,这将删除索引本身。相反,我得到的是 NEST 1.x 版。
任何指向文档的链接或有关代码的任何帮助都将非常有帮助。
谢谢你。
Rob*_*Rob 13
它公开了负责从elasticsearch中删除文档的elasticsearch delete API。
如果你想删除索引,你可以这样做
await client.Indices.DeleteAsync("index_name");
Run Code Online (Sandbox Code Playgroud)
希望有帮助。