Elasticsearch.Nest 教程系列 9-2 转换:Relation names inference | 关系名推断
source link: https://blog.zhuliang.ltd/2020/01/backend/Elasticsearch-Nest-Relation-names-inference.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Elasticsearch.Nest 教程系列 9-2 转换:Relation names inference | 关系名推断
create: 2020-01-22 15:43:01 | update: 2020-01-23 12:15:44
本文总阅读量: 157 次
|
文章总字数: 345 字
|
阅读约需: 1 分钟
- 本系列博文是“伪”官方文档翻译(更加本土化),并非完全将官方文档进行翻译,而是在查阅、测试原始文档并转换为自己真知灼见后的“准”翻译。有不同见解 / 说明不周的地方,还请海涵、不吝拍砖 :)
- 官方文档见此:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/introduction.html
- 本系列对应的版本环境:[email protected],[email protected],IDE 和开发平台默认为 VS2019,.NET CORE 2.1
当你使用子父级关系的时候,需要将子父级文档索引(添加)到同一个索引中,在 ES 5.x 的时候,你可以通过 / 中的 来进行指定,但从 ES7 开始,已经没有 type 一说(type=_doc),这个时候,你需要用 RelationName 来进行代替。
- 关于子父级文档跟 RelationName 的使用,可以见此博文:NEST 教程系列 4-5 映射:Parent/Child relationships | 子父级关系映射
var settings = new ConnectionSettings()
.DefaultMappingFor<CommitActivity>(m => m
.IndexName("projects-and-commits")
.RelationName("commits")
)
.DefaultMappingFor<Project>(m => m
.IndexName("projects-and-commits")
.RelationName("projects")
);
var resolver = new RelationNameResolver(settings);
var relation = resolver.Resolve<Project>();
relation.Should().Be("projects");
relation = resolver.Resolve<CommitActivity>();
relation.Should().Be("commits");
- RelationName 通过 DefaultTypeNameInferrer 使用一个 string 来表示转换后的 CLR 类型。
- 显式的配置 TypeName 不会影响原始 CLR 类型。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK