Search code examples
elasticsearchnest

ElasticSearch Connection settings


I just created ElasticSearch class and find some codes for elasticsearch connection settings but i know i am using NEST 7.0 and these codes i found are lower version than 7.0 so, how i can change to current version because i am getting some errors. Thanks in advance.

private static readonly ConnectionSettings connSettings = new ConnectionSettings(new Uri("http://localhost:9200/"))
                       .DefaultIndex("change_history")
                      .DefaultMappingFor(m => m
                       .Add(typeof(ChangeLog), "change_history"));
        private static readonly ElasticClient elasticClient = new ElasticClient(connSettings);

especially the defaultmapping part :)


Solution

  • The configuration options documentation has an example. Adapted for your example

    private static readonly ConnectionSettings connSettings = 
        new ConnectionSettings(new Uri("http://localhost:9200/"))
            .DefaultIndex("change_history")
            .DefaultMappingFor<ChangeLog>(m => m
                .IndexName("change_history")
            );
    
    private static readonly ElasticClient elasticClient = new ElasticClient(connSettings);