简体   繁体   中英

Nest Update By Id That Is Auto Generated By ElasticDb

I used Nest 6.X framework to manage ElasticSearch with c# At there I shared the result of nest query.

The c# code like this

_elasticSearchDb.Update(DocumentPath<myElasticType>.Id("Cq2jmGgB5bes6sABU8NP"), u => u.DocAsUpsert(true).Doc(myObject));

I want to update a document in an index by documentId that is generated by Elasticsearch as automaticly.

At this point, I don't have any problem.

Now think that I have 1 replica and 5 shard on elasticdb.

I have a few doubt when I want to execute this update progress. For example per day I send request to elasticsearch in different time as total 5000 request at the end of the day.

At this point, Can I have any performance problem on elastic db?

Here is the Elaastic Raw Query Request and response that genarated by Nest

Note: myElasticIndex and myElasticType terms used as dummny

Valid NEST response built from a successful low level call on POST: /myElasticIndex/myElasticType/Cq2jmGgB5bes6sABU8NP/_update
# Audit trail of this API call:
 - [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.0189528
# Request:
{
  "doc_as_upsert": true,
  "doc": {
    "person": "Eyup Can ARSLAN",
    "recordDate": "2019-01-29",
    "field3": "field3 data",
    "field4": "field 4 data"
  }
}


# Response:
{
  "_index": "myElasticIndex",
  "_type": "myElasticType",
  "_id": "Cq2jmGgB5bes6sABU8NP",
  "_version": 3,
  "result": "noop",
  "_shards": {
    "total": 0,
    "successful": 0,
    "failed": 0
  }
}

If you have the documents that you wish to upsert, and their ids, you can send them in batches with the Bulk API

var client = new ElasticClient();

var updates = new Dictionary<string, object>
{
    { "id1", new { foo = "bar" } },
    { "id2", new { foo = "baz" } }
};

var bulkResponse = client.Bulk(b => 
{
    b.Index("my_index").Type("my_type");

    foreach(var update in updates)
    {
        b.Update<object>(u => u
            .Id(update.Key)
            .DocAsUpsert()
            .Doc(update.Value)
        );
    }   

    return b;
});

The TValue generic parameter of updates can be your POCO type. This sends the following request

POST http://localhost:9200/my_index/my_type/_bulk
{"update":{"_id":"id1"}}
{"doc_as_upsert":true,"doc":{"foo":"bar"}}
{"update":{"_id":"id2"}}
{"doc_as_upsert":true,"doc":{"foo":"baz"}}

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