【问题标题】:NEST ElasticSearch Delete typeNEST ElasticSearch 删除类型
【发布时间】:2015-05-21 07:46:50
【问题描述】:

如果有人告诉我使用 NEST 删除特定类型的所有数据的正确方法,我将不胜感激。 我的 elasticsearch 中有一个索引和两种类型,我希望能够在需要时删除一种或另一种类型的所有数据。

我现在的想法是

ElasticClient.DeleteByQuery<ISearchData>(q => q.Index(indexName).Type(type.ToString()).Query(qu => qu.Bool(b => b.Must(m => m.MatchAll()))));

提前致谢。

【问题讨论】:

标签: .net nest


【解决方案1】:

试试这个:

var deleteByQuery = client.DeleteByQuery<Document>(d => d.MatchAll());

更新:

如果您使用一个类来存储两种类型的文档,您可以使用.Type() 参数指定您要删除哪一种。

client.DeleteByQuery<Document>(descriptor => descriptor.Type("type1").Query(q => q.MatchAll()));

我的例子:

client.Index(new Document {Id = 2}, descriptor => descriptor.Type("type1"));
client.Index(new Document {Id = 1}, descriptor => descriptor.Type("type1"));
client.Index(new Document {Id = 2}, descriptor => descriptor.Type("type2"));

client.Refresh();

client.DeleteByQuery<Document>(descriptor => descriptor.Type("type1").Query(q => q.MatchAll()));

【讨论】:

  • 感谢您的回复。但是我在两种不同的 Elastic Search 类型中有相同 C# 类型的文档,所以如果我按照您的建议,当我只需要删除一个类型时,我会删除这两种类型。
猜你喜欢
  • 1970-01-01
  • 2013-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-04
  • 2020-10-27
相关资源
最近更新 更多