Yes, you can name the type in Elasticsearch differently to your POCO a few different ways
1.Using the ElasticsearchType attribute applied to NestedMessage and specifying the Name property
[ElasticsearchType(Name="message")]
public class NestedMessage
{
}
2.Using InferMappingFor<T>() on ConnectionSettings
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.InferMappingFor<NestedMessage>(m => m
.TypeName("message")
);
var client = new ElasticClient(settings);
client.CreateIndex("index-name", s => s
.Mappings(ms => ms
.Map<NestedMessage>(m => m
.AutoMap()
)
)
);
3.Using .MapDefaultTypeNames() on ConnectionSettings (although this will be removed in future, InferMappingFor<T>() is the way to go. Listed here for completeness)
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.MapDefaultTypeNames(d => d
.Add(typeof(NestedMessage), "message")
);
var client = new ElasticClient(settings);
client.CreateIndex("index-name", s => s
.Mappings(ms => ms
.Map<NestedMessage>(m => m
.AutoMap()
)
)
);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.