如何使用 NEST 7.4.1 删除索引?

How do I delete an Index using NEST 7.4.1?

我是 Elastic search 的新手,我编写了代码来索引城市列表。我正在为 chrome 使用 "elasticsearch head" 附加组件来检查和操作索引和 _doc。

虽然正确生成了 doc 的索引和 CRUD 操作,但我不得不通过 elastic-search 插件手动删除索引。

我想先检查索引,如果有可用的索引,删除它,然后创建索引并重新索引城市列表。这就是我想要做的。但是在 Delete() 方法中出现错误

argument 1: cannot convert from string to 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;
        }

我搜索了 Elastic 搜索文档,但在 NEST 7.4.1 文档中找不到任何 API,这将删除 index 本身。 相反,我得到的是 NEST 版本 1.x.

任何 link 文档或有关代码的任何帮助都将非常有帮助。

谢谢。

client.Delete方法说明可以看出

它公开了 elasticsearch delete API,它负责从 elasticsearch 中删除文档。

如果你想删除索引,你可以使用

await client.Indices.DeleteAsync("index_name");

希望对您有所帮助。