WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Type name inference
editType name inference
editType 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
editA 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
editSimilarly 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
editYou 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");