Type name inference

edit

Type names are resolved in NEST by default, by lowercasing the CLR type name

var settings = new ConnectionSettings();
var resolver = new TypeNameResolver(settings);
var type = resolver.Resolve<Project>();
type.Should().Be("project");

Applying a type name with ElasticsearchTypeAttribute

edit

A type name can be applied for a CLR type, using the Name property on ElasticsearchTypeAttribute

[ElasticsearchType(Name = "attributed_project")]
public class AttributedProject { }

var settings = new ConnectionSettings();
var resolver = new TypeNameResolver(settings);
var type = resolver.Resolve<AttributedProject>();
type.Should().Be("attributed_project");

Applying a type name with DataContractAttribute

edit

Similarly to ElasticsearchTypeAttribute, a type name can be applied for a CLR type, using the Name property on System.Runtime.Serialization.DataContractAttribute

[DataContract(Name = "data_contract_project")]
public class DataContractProject { }

var settings = new ConnectionSettings();
var resolver = new TypeNameResolver(settings);
var type = resolver.Resolve<DataContractProject>();
type.Should().Be("data_contract_project");

Override type name inferrer

edit

You can provide a delegate to override the default type name inferrer for types

var settings = new ConnectionSettings()
    .DefaultTypeNameInferrer(t=>t.Name.ToLower() + "-suffix");
var resolver = new TypeNameResolver(settings);
var type = resolver.Resolve<Project>();
type.Should().Be("project-suffix");