简体   繁体   English

如何使用 Elasticsearch NEST 动态索引文档?

[英]How to index a document using Elasticsearch NEST dynamically?

I want to put documents from different customers to different indexes in Elasticsearch.我想将来自不同客户的文档放到 Elasticsearch 中的不同索引中。 Documents have some common part in structure and a part that vary from customer to customer named Data .文档在结构上有一些共同的部分和一个因客户而异的部分,名为Data

C# C#

class Entity
{
    public Guid CustomerId { get; set; }
    public IDictionary<string, object> Data { get; set; }
}

JSON JSON

{
    "customerId": "10000000-0000-0000-0000-000000000000",
    "data":  {......}
}

Say we have 10000 "customers" with a million of documents for each.假设我们有 10000 个“客户”,每个客户都有一百万份文档。 "Customers" may be created and deleted dynamically. “客户”可以动态创建和删除。

Is it good idea to put documents from different customers to different indexes in Elasticsearch?将来自不同客户的文档放到 Elasticsearch 中的不同索引中是个好主意吗?

Is it possible to create a new index in Elasticsearch based on customerId field of inserted document dynamically?是否可以根据插入文档的customerId字段在 Elasticsearch 中动态创建新索引? How to do it using.Net client?使用.Net客户端怎么做?

I'm looking for something like:我正在寻找类似的东西:

var index = entity.CustomerId;
client.CreateDocument<Entity>(entity, index);

PS I'm using Elasticsearch v7.6 PS我正在使用Elasticsearch v7.6

Well, I found an answer.嗯,我找到了答案。 Anyway would be nice if someone comment it how is it good strategically.无论如何,如果有人评论它在战略上有多好,那就太好了。

Here we go:这里我们 go:

 var indexName = entity.CustomerId.ToString();
 var request = new IndexRequest<Entity>(entity, indexName);
 client.Index<Entity>(entity);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM