2
在my usecase我试图同步两个Elasticsearch索引。由于版本控制,这是非常实用的quite simple。不过,我想在我这样做的时候随时写作。如何(暂时)阻止Elasticsearch删除已删除的文档?
好了,所以我想按时间顺序执行的步骤:
- 客户写(索引,删除,更新),以簇群C1
- 创建新的索引C2(客户不断写信给C1)从簇群C1
- 将数据复制到C2(客户不断写信给C1)
- 开关客户C2
- 从C1到C2的变化同步(客户端保持写入C2)
- 关机c1
步骤#5是我目前正在查看的步骤。我必须确保写入c2的更改不会被来自c1的数据覆盖。使用版本控制对于写入来说非常简单,因为索引操作将失败(VersionConflictEngineException)。假设以下情况:
- 文档被后#3(在C1 V2,C2上V1)
- 同一文档后右#4(在C1 V2删除,C2上删除更新于C1右)
- 同步将尝试重新索引上C2 V2
我知道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}
问题显然是“等待一段时间”的部分。我将不得不依赖于已删除的文档不知道的时间。因此,我需要通过禁止在运行#5时删除任何已删除的文档来控制这一时间。你会如何做到这一点?
Crossposted到Elasticsearch group(这related question)
感谢您的回答。但似乎动态地改变这个设置是被打破的。代码中的相应字段是'org.elasticsearch.index.engine.robin.RobinEngine.gcDeletesInMillis',它只在之前的信息日志'“将index.gc_deletes从[{}]更新为[{}]]''后修改。这条线永远不会被记录。 – sfussenegger
重新开放索引按预期工作 – sfussenegger
我已经打开[#3396](https://github.com/elasticsearch/elasticsearch/issues/3396) – sfussenegger