弹性搜索中数据继承的最佳方法是什么?
What is best approach for data inheritation in elasticsearch?
我有一个 parent class 和两个 child 像这样:
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; }
}
有一个问题:将这两个继承的class存储在ElasticSearch中的同一个Index中是不是一个好方法?
我看到有一个 _type 属性 在我的文档存储在数据库中后添加到我的文档中,但它始终具有“doc”值。
我测试了这段代码来填充它,但它似乎无法正常工作。
await ElasticClient.IndexAsync<FirstChild>(child, m => m.Index(IndexName));
此外,我在 SO 上发现了这个关于从数据库中检索我的条目的问题,但它已经过时并且 API 已更改且无法访问。
我想知道在同一索引中存储同级数据是否是一种好方法,我该如何正确执行此操作。
从 ES 6.0 开始,它在同一个索引中是 not possible anymore to store multiple types,即您所指的 _type
字段将始终是 doc
或 _doc
.在 ES 8.0 中,_type
字段将被完全删除。
但是,如果这对您的用例有意义,您仍然可以决定使用文档中存在的 custom type
field 将多个类型存储在单个索引中。
您应该努力只在相同的索引中存储共享相同(或非常相似)映射的数据,Parent
、FirstChild
和 [ 似乎并非如此=17=],但如果您在 类 中添加 public string type
属性,您仍然可以这样做。
我有一个 parent class 和两个 child 像这样:
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; }
}
有一个问题:将这两个继承的class存储在ElasticSearch中的同一个Index中是不是一个好方法? 我看到有一个 _type 属性 在我的文档存储在数据库中后添加到我的文档中,但它始终具有“doc”值。 我测试了这段代码来填充它,但它似乎无法正常工作。
await ElasticClient.IndexAsync<FirstChild>(child, m => m.Index(IndexName));
此外,我在 SO 上发现了这个关于从数据库中检索我的条目的问题,但它已经过时并且 API 已更改且无法访问。
我想知道在同一索引中存储同级数据是否是一种好方法,我该如何正确执行此操作。
从 ES 6.0 开始,它在同一个索引中是 not possible anymore to store multiple types,即您所指的 _type
字段将始终是 doc
或 _doc
.在 ES 8.0 中,_type
字段将被完全删除。
但是,如果这对您的用例有意义,您仍然可以决定使用文档中存在的 custom type
field 将多个类型存储在单个索引中。
您应该努力只在相同的索引中存储共享相同(或非常相似)映射的数据,Parent
、FirstChild
和 [ 似乎并非如此=17=],但如果您在 类 中添加 public string type
属性,您仍然可以这样做。