Es gibt ein paar Optionen würde geschätzt, die Sie haben für einen anderen Typnamen der einer NEST Angabe wird von dem POCO Namen entnehmen
1.Verwenden der Map<T>(TypeName type, Func<TypeMappingDescriptor<T>, ITypeMapping>>)
Überlast-
var createIndexResponse = client.CreateIndex("testindex", a => a
.Mappings(f => f
.Map<BankPaymentLogModel>("my-type", b => b
.Properties(c => c
.String(d => d
.Name(e => e.testProperty)
)
)
)
)
);
Die Verwendung dieser Methode würde jedoch bedeuten, dass Sie für jede Anforderung, bei der BankPaymentLogModel
POCO verwendet wird, .Type("my-type")
aufrufen müssen, damit derselbe Typname in der Anforderung gesendet wird. So können die folgenden Optionen besser
2.Use ElasticsearchTypeAttribute
auf BankPaymentLogModel
Typ
[ElasticsearchType(Name = "my-type")]
public class BankPaymentLogModel
{
public string testProperty { get; set; }
}
var createIndexResponse = client.CreateIndex("testindex", a => a
.Mappings(f => f
.Map<BankPaymentLogModel>(b => b
.Properties(c => c
.String(d => d
.Name(e => e.testProperty)
)
)
)
)
);
3.oder den Typnamen angeben, wenn Sie Attribute nicht mögen, ein Standardtyp Name kann auf konfiguriert werden ConnectionSettings
für BankPaymentLogModel
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
.InferMappingFor<BankPaymentLogModel>(m => m
.TypeName("my-type")
);
var client = new ElasticClient(connectionSettings);
var createIndexResponse = client.CreateIndex("testindex", a => a
.Mappings(f => f
.Map<BankPaymentLogModel>(b => b
.Properties(c => c
.String(d => d
.Name(e => e.testProperty)
)
)
)
)
);
Alle drei oben genannten Optionen produzieren folgende Anfrage json
PUT http://localhost:9200/testindex
{
"mappings": {
"my-type": {
"properties": {
"testProperty": {
"type": "string"
}
}
}
}
}