ELASTIC SEARCH : DELETE INDEX USING NEST IN .NET

Standard

For connecting with elastic nodes read this: CREATE INDEX USING NEST IN .NET

For inserting documents read this: INSERT DOCUMENTS IN INDEX USING NEST IN .NET

In order to delete index use DeleteIndex API with index name as parameter

C# Snippet

Snippet

using System;
using Nest;
 
namespace ElasticSearchDemo
{
    class SampleProgram
    {
        public static Uri EsNode;
        public static ConnectionSettings EsConfig;
        public static ElasticClient EsClient;
        void Main(string[] args)
        {
            EsNode = new Uri("http://localhost:9200/");
            EsConfig = new ConnectionSettings(EsNode);
            EsClient = new ElasticClient(EsConfig);
 
            var settings = new IndexSettings { NumberOfReplicas = 1, NumberOfShards = 2 };
 
            var indexConfig = new IndexState
            {
                Settings = settings
            };
 
            if (!EsClient.IndexExists("employee").Exists)
            {
                EsClient.CreateIndex("employee", c => c
                    .InitializeUsing(indexConfig)
                    .Mappings(m => m.Map<Employee>(mp => mp.AutoMap()))
                );
            }
 
            DeleteIndex();
 
        }
 
        public static object DeleteIndex()
        {
            var response = EsClient.DeleteIndex("employee");
            return response;
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s