通过id从ElasticSearch索引中删除文档

khe*_*eya 4 elasticsearch nest

我有一个弹性搜索文档.我正在尝试实现一种方法,我可以使用NEST客户端指定字符串id以从索引中删除文档.

这是我要删除的索引文档:

"hits":[{"_index":"movies","_type":"list","_id":"100","_score":0.6349302, "_source" : {
  "owner": "Bob",
  "tags": "Bobita",
  "title": "Movie clips of Bob"
}}
Run Code Online (Sandbox Code Playgroud)

这是我的C#代码,它不会删除doc.它说id为NULL.

Uri localhost = new Uri("http://localhost:9200");
            var setting = new ConnectionSettings(localhost);
            setting.SetDefaultIndex("movies");
            var client = new ElasticClient(setting);

            IDeleteResponse resp = client.Delete("100");                

            if (!resp.Found)
            {
                logger.Error("Failed to delete index with id=100");
            }
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

Gre*_*uka 5

我认为这里的问题是NEST无法正确推断文档的Id属性,因为您没有指定类型.

如果可能的话,试试这个:

client.Delete<YourMovieType>("100");
Run Code Online (Sandbox Code Playgroud)