gpt4 book ai didi

elasticsearch - 如何使用ReST API在Elastic Search中保持重复数据计数?

转载 作者:行者123 更新时间:2023-12-02 22:34:06 25 4
gpt4 key购买 nike

如何使用ReST API在Elastic Search中保持重复数据计数?
可以在Elastic Search中使用相同的索引保留相同的数据,但是我们应该能够看到它的各种版本?
并且在概述区域中应显示
docs 5(6)。

最佳答案

只要使用不同的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
}

关于elasticsearch - 如何使用ReST API在Elastic Search中保持重复数据计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10684541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com