Search code examples
c#elasticsearchnest

ElasticSearch and NEST: How do you purge all documents from an index?


I know how to delete an entire ElasticSearch index, but how do you purge all documents from an index?

My Motivation: I'd like to have a "ReIndex" method that purges the entire contents of an index so that I can reload all documents.

ElasticSearch syntax would be helful. NEST syntax would be even better.


Solution

  • I was looking for something similar in Nest and I thought I'd put the syntax here for anyone looking:

    var node = new Uri("http://localhost:9200");
    var settings = new ConnectionSettings(node);
    var client = new ElasticClient(settings);
    
    client.DeleteByQuery<ElasticsearchProject>(del => del
        .Query(q => q.QueryString(qs=>qs.Query("*")))
    );