elasticsearch - 如何使用 Elasticsearch NEST 动态索引文档?
问题描述
我想将来自不同客户的文档放到 Elasticsearch 中的不同索引中。文档在结构上有一些共同的部分和一个因客户而异的部分,名为Data。
C#
class Entity
{
public Guid CustomerId { get; set; }
public IDictionary<string, object> Data { get; set; }
}
JSON
{
"customerId": "10000000-0000-0000-0000-000000000000",
"data": {......}
}
假设我们有 10000 个“客户”,每个客户都有一百万份文档。“客户”可以动态创建和删除。
将来自不同客户的文档放到 Elasticsearch 中的不同索引中是个好主意吗?
是否可以根据插入文档的customerId字段在 Elasticsearch 中动态创建新索引?如何使用.Net客户端来做到这一点?
我正在寻找类似的东西:
var index = entity.CustomerId;
client.CreateDocument<Entity>(entity, index);
PS 我正在使用 Elasticsearch v7.6
解决方案
嗯,我找到了答案。无论如何,如果有人评论它在战略上有多好,那就太好了。
开始了:
var indexName = entity.CustomerId.ToString();
var request = new IndexRequest<Entity>(entity, indexName);
client.Index<Entity>(entity);
推荐阅读
- php - Envato API 从服务器发送 POST 请求
- api - POST Nest API 以使用 ESP8266 或 Arduino 获取访问令牌
- python - 如何创建位列表的列表?
- ios - 在 UITextField 上可视化模式
- html - 如何为多个元素使用 circleType
- r - 如果 R 中存在链接,则插入 Youtube 链接
- javascript - 当服务器大多处于超时状态时,他们是否有任何方式来获取/更新网站的特定 div 内容?
- algorithm - 自动完成算法的新特性
- opengl - OpenGL没有将最近的片段绘制到相机
- bash - 如果条件不起作用将项目与 bash 中的 __ 进行比较