在映射中设置自定义类型名称

Set custom type name in mapping

我需要创建一个具有自定义名称的文档映射。目前,我的文档在 CreateIndexDescriptor 对象上有以下映射:

.Mappings(m => m
  .Map<MyDocType>(mDetails => mDetails.AutoMap()));

这会创建一个名为 mydoctype 的文档映射。我如何修改它以便创建类型名称为 my_doctype?

的文档

在 NEST 7.x 中,这是不可能的 - 文档类型将为 _docin line with the roadmap for the removal of mapping types

在 NEST 6.x 中,您可以 specify the type name to use in a few different ways:

  1. 在 POCO

    上使用 ElasticsearchTypeAttribute
    [ElasticsearchType(Name = "my_doctype")]
    public class MyDocType{ }
    
  2. 在 POCO

    上使用 DataContractAttribute
    [DataContract(Name = "my_doctype")]
    public class MyDocType{ }
    
  3. 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);