简体   繁体   English

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

[英]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. 我使用Nest 6.X框架通过c#管理ElasticSearch,在那儿我共享了嵌套查询的结果。

The c# code like this 像这样的C#代码

_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. 我想通过Elasticsearch自动生成的documentId更新索引中的文档。

At this point, I don't have any problem. 在这一点上,我没有任何问题。

Now think that I have 1 replica and 5 shard on elasticdb. 现在以为我在elasticdb上有1个副本和5个分片。

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. 例如,每天我在不同的时间向弹性搜索发送请求,一天结束时总共发送5000个请求。

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 这是Nest生成的Elaastic原始查询请求和响应

Note: myElasticIndex and myElasticType terms used as dummny 注意: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
  }
}

If you have the documents that you wish to upsert, and their ids, you can send them in batches with the Bulk API 如果您有想要更新的文档及其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;
});

The TValue generic parameter of updates can be your POCO type. 更新的TValue通用参数可以是您的POCO类型。 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"}}

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

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