在我的用例中,我正在尝试同步两个Elasticsearch索引.由于版本控制,这非常简单.但是,在我这样做的时候,我想随时继续写作.
好的,所以我想按时间顺序执行的步骤:
第5步是我目前正在考虑的步骤.我必须确保写入c2的更改不会被来自c1的数据覆盖.使用版本控制对于写入来说相当简单,因为索引操作将失败(VersionConflictEngineException).假设以下情况:
我知道elasticsearch会将已删除的文档保留一段时间:
# index document 1:4
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"ok":true,"_index":"test","_type":"test","_id":"1","_version":4}
# delete document 1:6
$ curl -XDELETE 'http://localhost:9200/test/test/1?version=6&version_type=external'
{"ok":true,"found":true,"_index":"test","_type":"test","_id":"1","_version":6}
# index document 1:4 (ERROR!)
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"error":"VersionConflictEngineException[[test][2] [test][1]: version conflict, current [6], provided [4]]","status":409}
# wait some time
# index document 1:4 (SUCCESS!)
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"ok":true,"_index":"test","_type":"test","_id":"1","_version":4}
Run Code Online (Sandbox Code Playgroud)
问题显然是"等待一段时间"的一部分.我将不得不依赖已删除的文件一段时间.因此,我需要通过在运行#5时禁止删除任何已删除文档来控制此时间.你会怎么做?
交叉到Elasticsearch小组(以及此相关问题)
| 归档时间: |
|
| 查看次数: |
1287 次 |
| 最近记录: |