File tree Expand file tree Collapse file tree 3 files changed +75
-2
lines changed
docs/rest_apis/document_apis Expand file tree Collapse file tree 3 files changed +75
-2
lines changed Original file line number Diff line number Diff line change @@ -918,7 +918,7 @@ npm run docs:dev
918918 - :heavy_check_mark : 词向量 API [ :link : ] ( https://elasticsearch.bookhub.tech/rest_apis/document_apis/termvectors )
919919 - :heavy_check_mark : 多词向量 API [ :link : ] ( https://elasticsearch.bookhub.tech/rest_apis/document_apis/multi_termvectors )
920920 - :heavy_check_mark : ?refresh [ :link : ] ( https://elasticsearch.bookhub.tech/rest_apis/document_apis/refresh )
921- - Optimistic concurrency control
921+ - : heavy_check_mark : 乐观并发控制 [ : link : ] ( https://elasticsearch.bookhub.tech/rest_apis/document_apis/optimistic_concurrency_control )
922922 - Enrich APIs
923923 - Put enrich policy
924924 - Delete enrich policy
Original file line number Diff line number Diff line change 1+ # 乐观并发控制
2+
3+ Elasticsearch 是分布式的。当创建、更新或删除文档时,文档的新版本必须复制到集群中的其他节点。Elasticsearch 也是异步和并发的,这意味着这些复制请求是并行发送的,而且可能会不按顺序到达目的地。Elasticsearch 需要一种方法来确保文档的旧版本永远不会覆盖新版本。
4+ 为了确保文档的旧版本不会覆盖新版本,对文档执行的每次操作都会由负责协调更改的主分片分配一个序列号。每次操作都会增加序列号,因此较新操作的序列号会高于较旧操作的序列号。然后,Elasticsearch 可以使用操作的序列号来确保较新的文档版本不会被分配给它的序列号较小的变更所覆盖。
5+
6+ 例如,下面的索引命令将创建一个文档,并为其分配一个初始序列号和主要词:
7+
8+ ``` bash
9+ PUT products/_doc/1567
10+ {
11+ " product" : " r2d2" ,
12+ " details" : " A resourceful astromech droid"
13+ }
14+ ```
15+
16+ 你可以在响应的 ` _seq_no ` 和 ` _primary_term ` 字段中看到分配的序列号和主要词:
17+
18+ ``` json
19+ {
20+ "_shards" : {
21+ "total" : 2 ,
22+ "failed" : 0 ,
23+ "successful" : 1
24+ },
25+ "_index" : " products" ,
26+ "_id" : " 1567" ,
27+ "_version" : 1 ,
28+ "_seq_no" : 362 ,
29+ "_primary_term" : 2 ,
30+ "result" : " created"
31+ }
32+ ```
33+
34+ Elasticsearch 会记录上次更改其存储的每个文档的操作的序列号和主要词。序列号和主要词会在 [ 获取 API] ( /rest_apis/document_apis/get ) 响应的 ` _seq_no ` 和 ` _primary_term ` 字段中返回:
35+
36+ ``` bash
37+ GET products/_doc/1567
38+ ```
39+
40+ 返回:
41+
42+ ``` json
43+ {
44+ "_index" : " products" ,
45+ "_id" : " 1567" ,
46+ "_version" : 1 ,
47+ "_seq_no" : 362 ,
48+ "_primary_term" : 2 ,
49+ "found" : true ,
50+ "_source" : {
51+ "product" : " r2d2" ,
52+ "details" : " A resourceful astromech droid"
53+ }
54+ }
55+ ```
56+
57+ 注意:通过设置 [ ` seq_no_primary_term ` 参数] ( /rest_apis/search_apis/search ) ,搜索 API 可以返回每个搜索结果的 ` _seq_no ` 和 ` _primary_term ` 。
58+
59+ 序列号和主要术语可唯一标识一项更改。通过记下返回的序列号和主要术语,可以确保只有在检索后没有其他更改的情况下才更改文档。这可以通过设置[ 索引 API] ( /rest_apis/document_apis/docs_index ) 、[ 更新 API] ( /rest_apis/document_apis/update ) 或[ 删除 API] ( /rest_apis/document_apis/delete ) 的 ` if_seq_no ` 和 ` if_primary_term ` 参数来实现。
60+
61+ 例如,下面的索引调用将确保在文档中添加一个标签,而不会丢失描述的任何潜在更改或其他 API 添加的另一个标签:
62+
63+ ``` bash
64+ PUT products/_doc/1567? if_seq_no=362& if_primary_term=2
65+ {
66+ " product" : " r2d2" ,
67+ " details" : " A resourceful astromech droid" ,
68+ " tags" : [ " droid" ]
69+ }
70+ ```
71+
72+ > [ 原文链接] ( https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html )
Original file line number Diff line number Diff line change @@ -168,7 +168,8 @@ const sidebars = {
168168 'rest_apis/document_apis/reindex' ,
169169 'rest_apis/document_apis/termvectors' ,
170170 'rest_apis/document_apis/multi_termvectors' ,
171- 'rest_apis/document_apis/refresh'
171+ 'rest_apis/document_apis/refresh' ,
172+ 'rest_apis/document_apis/optimistic_concurrency_control'
172173 ]
173174 } ,
174175 {
You can’t perform that action at this time.
0 commit comments