简体   繁体   中英

How to index a document using Elasticsearch NEST dynamically?

I want to put documents from different customers to different indexes in Elasticsearch. Documents have some common part in structure and a part that vary from customer to customer named Data .

C#

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

JSON

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

Say we have 10000 "customers" with a million of documents for each. "Customers" may be created and deleted dynamically.

Is it good idea to put documents from different customers to different indexes in Elasticsearch?

Is it possible to create a new index in Elasticsearch based on customerId field of inserted document dynamically? How to do it using.Net client?

I'm looking for something like:

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

PS I'm using Elasticsearch v7.6

Well, I found an answer. Anyway would be nice if someone comment it how is it good strategically.

Here we go:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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