Elasticsearch.NET 版本 7 - 如何创建索引 [英] Elasticsearch.NET version 7 - How to Create Index
问题描述
在 Elasticsearch.NET 6.x 中,可以使用 IElasticClient
方法创建索引:
In Elasticsearch.NET 6.x, it is possible create an index using IElasticClient
method:
var response = elasticClient.Create(
"my-index-name",
index => index .Mappings(
ms => ms.Map<MyDocumentType>(
x => x.AutoMap()
)
)
);
方法在 Elasticsearch.NET 版本 7 中被删除.
Method is removed in Elasticsearch.NET version 7.
推荐答案
在 Elasticsearch.NET 版本 7 中与索引操作相关的方法被移到 IndicesNamespace
中,所以 IndexExists
方法已移至:
In Elasticsearch.NET version 7 methods related to indices operations are moved into IndicesNamespace
, so IndexExists
method has been moved to:
var response = elasticClient.Indices.Create(IndexName,
index => index.Map<ElasticsearchDocument>(
x => x.AutoMap()
));
另请注意,Map(...)
方法不再嵌套在 Mappings(...)
方法内部.原因是 Elasticsearch
服务器版本 7 支持不支持每个索引的多种类型(请参阅 删除映射类型),因此每个索引一个 Map
方法就足够了.
Also note, that Map(...)
method is no longer nested inside of Mappings(...)
method. Reason is that Elasticsearch
server version 7 supports does not support multiple types per index (see Removal of mapping types), so one Map
method per index is sufficient.
同样,不同的方法已移至各自的命名空间:
Similarly, different methods have been moved to their own namespaces:
- 猫
- 集群
- 图表
- SQL
- 节点
- 等等...
这篇关于Elasticsearch.NET 版本 7 - 如何创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!