我保持两个脚本运行,一个向索引发送批量请求:
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,对吧?
是否有可能按查询更新成功但有时会发生批量冲突和失败?