[英]ElasticSearch NEST Delete all document
我正在使用ElastciSearch 2.3.0
我正在嘗試使用.net和NEST針對特定索引從ElasticSearch中刪除文檔。
我只想刪除所有文檔,而不要刪除_mapping
DeleteByQueryRequest r = new DeleteByQueryRequest(new IndexName() { Name = indexName });
r.QueryOnQueryString = "*";
var response = client.DeleteByQuery(r);
我嘗試通過使用上面的代碼來執行此操作,但是它不起作用。
請建議上述代碼有什么問題或如何完成。
感謝您的幫助。
不要使用通過查詢刪除它,因為彈性2.0是有充分的理由,它已成為插件。 您可以輕松擺脫內存異常。 您應該刪除整個索引並重新創建映射
static void Main(string[] args)
{
ElasticClient db = new ElasticClient(new Uri("http://localhost.fiddler:9200"));
db.IndexMany(Enumerable.Range(0, 100).Select(i => new Data { Id = i, Name = "Name" + i }), "test_index");
var mappings = db.GetMapping<Data>();
var delete = db.DeleteIndex(new DeleteIndexRequest("test_index"));
var indexMapping = mappings.IndexTypeMappings["test_index"].ToDictionary(k => k.Key, v => (ITypeMapping)v.Value);
db.CreateIndex(new CreateIndexRequest("test_index")
{
Mappings = new Mappings(indexMapping)
});
Console.ReadLine();
}
class Data
{
public int Id { get; set; }
public string Name { get; set; }
}
索引的原始副本
var res = db.LowLevel.IndicesGetMapping<JObject>("test_index");
var delete = db.DeleteIndex(new DeleteIndexRequest("test_index"));
var mappings = res.Body["test_index"].ToString();
var create = db.LowLevel.IndicesCreate<JObject>("test_index", mappings);
如果您確實需要安裝插件sudo bin / plugin,請按查詢刪除
有效。 非常感謝。
var res = db.LowLevel.IndicesGetMapping<JObject>("test_index");
var delete = db.DeleteIndex(new DeleteIndexRequest("test_index"));
var mappings = res.Body["test_index"].ToString();
var create = db.LowLevel.IndicesCreate<JObject>("test_index", mappings);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.