3

Elasticsearch.Nest 教程系列 9-2 转换:Relation names inference | 关系名推断

 2 years ago
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.
neoserver,ios ssh client

Elasticsearch.Nest 教程系列 9-2 转换:Relation names inference | 关系名推断

create: 2020-01-22 15:43:01 | update: 2020-01-23 12:15:44 本文总阅读量: 157 次  |  文章总字数: 345 字  |  阅读约需: 1 分钟


当你使用子父级关系的时候,需要将子父级文档索引(添加)到同一个索引中,在 ES 5.x 的时候,你可以通过 / 中的 来进行指定,但从 ES7 开始,已经没有 type 一说(type=_doc),这个时候,你需要用 RelationName 来进行代替。

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 类型。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK