2
如何使用ReST API在彈性搜索中保持重複數據計數?
是否可以在彈性搜索中保持同一索引數據相同,但我們應該能夠看到它的各種版本? 和概覽區域中應顯示 文檔5(6)。如何使用ReST API在彈性搜索中保持重複數據計數?
是否可以在彈性搜索中保持同一索引數據相同,但我們應該能夠看到它的各種版本? 和概覽區域中應顯示 文檔5(6)。如何使用ReST API在彈性搜索中保持重複數據計數?
只要您使用不同的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
}
非常感謝你回答我的問題。假設我沒有專門提供id並保留系統生成的id。在這種情況下,相同的數據將以不同的id存儲,但版本將爲1,並且用於此目的的API(例如ReST API,Java API)沒有任何區別? – jayati
對。使用系統生成的ID將具有相同的效果。我只是以這種方式構建了這個例子,因爲你必須爲它提供一個REST PUT。 – drewr
非常感謝德魯。 – jayati