小编Ash*_*ope的帖子

如何使用 NEST 7.4.1 删除索引?

我是弹性搜索的新手,我编写了代码来索引城市列表。我正在使用 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}: …
Run Code Online (Sandbox Code Playgroud)

c# elasticsearch nest

6
推荐指数
1
解决办法
3984
查看次数

标签 统计

c# ×1

elasticsearch ×1

nest ×1