簡體   English   中英

由ElasticDb自動生成的ID的嵌套更新

[英]Nest Update By Id That Is Auto Generated By ElasticDb

我使用Nest 6.X框架通過c#管理ElasticSearch,在那兒我共享了嵌套查詢的結果。

像這樣的C#代碼

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

我想通過Elasticsearch自動生成的documentId更新索引中的文檔。

在這一點上,我沒有任何問題。

現在以為我在elasticdb上有1個副本和5個分片。

當我要執行此更新進度時,我有一些疑問。 例如,每天我在不同的時間向彈性搜索發送請求,一天結束時總共發送5000個請求。

在這一點上,我可以在彈性數據庫上有任何性能問題嗎?

這是Nest生成的Elaastic原始查詢請求和響應

注意:myElasticIndex和myElasticType術語用作傻瓜

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
  }
}

如果您有想要更新的文檔及其ID,則可以使用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;
});

更新的TValue通用參數可以是您的POCO類型。 這發送以下請求

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"}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM