簡體   English   中英

NEST ElasticSearch刪除類型

[英]NEST ElasticSearch Delete type

如果有人告訴我使用NEST刪除特定類型的所有數據的正確方法,我將不勝感激。 我在Elasticsearch中有一個索引,有兩種類型,我希望能夠在需要時刪除一種或另一種類型的所有數據。

我目前的想法是

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

提前致謝。

試試這個:

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()));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM