是否可以在弹性搜索中保留具有相同索引的相同数据,但我们应该能够看到它的各种版本? 它应该显示在概述区域 docs 5(6)。
答案 0 :(得分:1)
只要您使用不同的ID,就可以存储所需的文档版本。 (请注意,ES为您管理了_version
属性,但它仅用于解决冲突.ES并不能让您访问旧版本的文档。)
% curl -s -XPUT localhost:9200/test/foo/1 -d '{"yo":"brah","version":1}' | j
{
"_id": "1",
"_index": "test",
"_type": "foo",
"_version": 1,
"ok": true
}
% curl -s -XPUT localhost:9200/test/foo/2 -d '{"yo":"brah","version":2}' | j
{
"_id": "2",
"_index": "test",
"_type": "foo",
"_version": 1,
"ok": true
}
% curl -s localhost:9200/test/_search | j
{
"_shards": {
"failed": 0,
"successful": 5,
"total": 5
},
"hits": {
"hits": [
{
"_id": "1",
"_index": "test",
"_score": 1.0,
"_source": {
"version": 1,
"yo": "brah"
},
"_type": "foo"
},
{
"_id": "2",
"_index": "test",
"_score": 1.0,
"_source": {
"version": 2,
"yo": "brah"
},
"_type": "foo"
}
],
"max_score": 1.0,
"total": 2
},
"timed_out": false,
"took": 12
}