我保持两个脚本运行,其中一个向索引发送批量请求:
while true; do
s=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 10)
curl -s -X POST 'localhost:9200/test/_bulk' -H 'Content-Type: application/x-ndjson' -d \
'{ "update": { "_index": "test", "_id": "1" } }
{ "doc": { "name": "update", "foo": "'$s'" } }
{ "update": { "_index": "test", "_id": "2" } }
{ "doc": { "name": "update", "foo": "'$s'" } }
{ "update": { "_index": "test", "_id": "3" } }
{ "doc": { "name": "update", "foo": "'$s'" } }
'
echo ''
done另一个发送对这些文档的逐个查询更新请求(每次请求后我必须睡眠,因为如果请求发送得太频繁,它可能会与前一个请求冲突):
while true; do
s=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 10)
curl -s -X POST 'localhost:9200/test/_update_by_query' -H 'Content-Type: application/json' -d \
'{
"query": {
"match": {
"name": {
"query": "update"
}
}
},
"script": {
"lang": "painless",
"source": "ctx._source['"'foo'"'] = '"'$s'"'"
}
}'
echo ''
sleep 1
done从两个脚本的输出来看,批量响应中没有冲突失败。所有冲突都发生在按查询更新这一端。
根据冲突错误消息:version conflict, required seqNo [66], primary term [1]. current document has seqNo [67] and primary term [1],似乎是在将操作从主分片复制到副本时发生冲突。但bulk也需要这样做并增加seqNo,对吧?
有没有可能update-by-query成功,但批量冲突有时会失败?
发布于 2021-09-30 06:56:38
您的批量请求始终使用index命令,因此覆盖文档(如果有)或创建新文档,因此永远不会发生冲突。
按查询更新的请求是...嗯,更新,冲突只能发生在这一端。
如果您的更新请求是在批量请求覆盖现有文档之后发出的,则会发生冲突。
如果批量请求是在更新请求更新文档之后发出的,则不会发生任何操作,因为批量请求将覆盖更新请求所做的更改,因为它使用index命令。
https://stackoverflow.com/questions/69386830
复制相似问题