Hello There,

Please accept my apologies in advance for bad English. I do not have much knowledge of programming concepts and I am new to elasticsearch.

Preparing a sample using Elasticsearch NEST in ASP.NET MVC C#.

I have prepared a class with an static function which return ElasticClient.

    public class ElasticSeachConfiguration
        {
            public static ElasticClient ESContext()
            {                                        
                var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
                var client = new ElasticClient(settings);
                return client;
            }
    }

Now the problem is that when ever I need to communicate with elasticsearch I am using ElasticSeachConfiguration.ESContext() and each time it is creating new ConnectionSetting and new elastic client.

For example ->

    public void CreateEmployee(Employee emp)
            {
                ElasticSeachConfiguration.ESContext().Index(emp, i => i.Index("myindex").Type("employee").Id(emp.Id));
            }

    public void UpdateEmployee(Employee emp)
            {
                ElasticSeachConfiguration.ESContext().Index(emp, i => i.Index("myindex").Type("employee").Id(emp.Id));
     ElasticSeachConfiguration.ESContext().Update<Employee, object>(new DocumentPath<Employee>(emp.Id), u => u
                           .Index("myindex").Type("employee")
                           .Doc(emp));
            }

I am not feeling good about it .. I am sure I am making a blunder related to programming concepts .. I need your guidance .. please share your suggestions .. what should I explore so that I can understand the concepts to write classes in correct pattern .. to stop unnecessary execution of the code .. I hope my request is clear ..sharing temp link for sample code I prepared

https://expirebox.com/download/e8cd4d99c55541dc5e536651bf03c820.html

Thanks in advance.

---
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB