我是Elastic搜索的新手,我写了代码来索引城市列表。我使用“elasticsearch head”附加组件来检查和操作索引和_doc。
虽然文档的索引和CRUD操作是正确的,但我不得不通过ElasticSearch插件手动删除索引。
我想先检查索引,如果有可用的索引,就删除它,然后创建索引并重新索引City列表。这就是我想做的。但是在Delete()方法中得到一个错误,说
参数1:无法从字符串转换为嵌套。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;
}
我已经搜索了Elastic search文档,但在NEST 7.4.1文档中找不到任何API,这将删除 index 本身。相反,我得到的是NEST版本1.x。
任何指向文档的链接或任何有关代码的帮助都将非常有用。
谢谢大家。
2条答案
按热度按时间neekobn81#
从
client.Delete
方法描述中可以看到它暴露了elasticsearch delete API,负责从elasticsearch中删除文档。
如果你想删除索引,你可以用
希望能帮上忙。
vwhgwdsa2#
2023-04-12的最后一个版本如下代码工作: