【问题标题】:What is best approach for data inheritation in elasticsearch?elasticsearch中数据继承的最佳方法是什么?
【发布时间】:2021-06-15 03:14:09
【问题描述】:

我有一个父类和两个像这样的孩子:

public class Parent {
    public Guid Id { get; set; }
    public string Name { get; set; }
}

public class FirstChild {
    public string IdentityCode { get; set; }
}

public class OtherChild {
    public string RegistrationCode { get; set; }
}

有一个问题:将这两个继承的类存储在ElasticSearch内部的同一个Index中是否是一种好方法? 我看到有一个 _type 属性在我的文档存储在数据库中后被添加到它们中,但它始终具有“doc”值。 我测试了这段代码来填充它,但它似乎不是这样工作的。

await ElasticClient.IndexAsync<FirstChild>(child, m => m.Index(IndexName));

另外,我在 SO 上发现了这个问题,用于从数据库中检索我的条目,但它已经过时,API 已更改且无法访问。

我想知道将兄弟数据存储在同一个索引中是否是一种好方法,我该如何正确地做到这一点。

【问题讨论】:

    标签: c# elasticsearch .net-core nest


    【解决方案1】:

    从 ES 6.0 开始,它在同一索引内是 not possible anymore to store multiple types,即您所指的 _type 字段将始终是 doc_doc。在 ES 8.0 中,_type 字段将被完全删除。

    但是,如果这对您的用例有意义,您仍然可以决定使用文档中存在的 custom type field 将多个类型存储在单个索引中。

    您应该努力只存储共享相同(或非常相似)映射的相同索引数据,ParentFirstChildSecondChild 似乎并非如此,但如果您将public string type 属性添加到您的类中,您仍然可以这样做。

    【讨论】:

      猜你喜欢
      • 2020-02-10
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多