在映射中设置自定义类型名称
Set custom type name in mapping
我需要创建一个具有自定义名称的文档映射。目前,我的文档在 CreateIndexDescriptor 对象上有以下映射:
.Mappings(m => m
.Map<MyDocType>(mDetails => mDetails.AutoMap()));
这会创建一个名为 mydoctype 的文档映射。我如何修改它以便创建类型名称为 my_doctype?
的文档
在 NEST 7.x 中,这是不可能的 - 文档类型将为 _doc
、in line with the roadmap for the removal of mapping types。
在 NEST 6.x 中,您可以 specify the type name to use in a few different ways:
在 POCO
上使用 ElasticsearchTypeAttribute
[ElasticsearchType(Name = "my_doctype")]
public class MyDocType{ }
在 POCO
上使用 DataContractAttribute
[DataContract(Name = "my_doctype")]
public class MyDocType{ }
在 ConnectionSettings
上使用 .DefaultMappingFor<T>()
var settings = new ConnectionSettings()
.DefaultMappingFor<MyDocType>(m => m
.IndexName("my_doc_type_default_index")
.TypeName("my_doctype")
);
var client = new ElasticClient(settings);
我需要创建一个具有自定义名称的文档映射。目前,我的文档在 CreateIndexDescriptor 对象上有以下映射:
.Mappings(m => m
.Map<MyDocType>(mDetails => mDetails.AutoMap()));
这会创建一个名为 mydoctype 的文档映射。我如何修改它以便创建类型名称为 my_doctype?
的文档在 NEST 7.x 中,这是不可能的 - 文档类型将为 _doc
、in line with the roadmap for the removal of mapping types。
在 NEST 6.x 中,您可以 specify the type name to use in a few different ways:
在 POCO
上使用ElasticsearchTypeAttribute
[ElasticsearchType(Name = "my_doctype")] public class MyDocType{ }
在 POCO
上使用DataContractAttribute
[DataContract(Name = "my_doctype")] public class MyDocType{ }
在
上使用ConnectionSettings
.DefaultMappingFor<T>()
var settings = new ConnectionSettings() .DefaultMappingFor<MyDocType>(m => m .IndexName("my_doc_type_default_index") .TypeName("my_doctype") ); var client = new ElasticClient(settings);