gpt4 book ai didi

elasticsearch - Elasticsearch Minimum Aggreviate返回null

转载 作者:行者123 更新时间:2023-12-03 01:33:59 27 4
gpt4 key购买 nike

我有一个名为“posts”的elasticsearch索引。
http://127.0.0.1:9200/posts/doc/_count返回{"count":240000,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0}}

我正在尝试在“doc”类型中找到最低ID字段。谷歌搜索后,我相信我想要的工具是聚合。

大部分直接从official documentation复制和粘贴后,我开始使用它:

POST /posts/_search?size=0
{
"aggs" : {
"min_id" : { "min" : { "field" : "id" } }
}
}

使用 curl -X POST "localhost:9200/posts/_search?size=0" -H 'Content-Type: application/json' -d'{"aggs" : {"min_id" : { "min" : { "field" : "id" } }}}'提交请求。
结果如下:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 240000,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"min_id" : {
"value" : null
}
}
}

我相信 min_id的值不应为null。

当我搜索size = 1时,得到以下信息:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 240000,
"max_score" : 1.0,
"hits" : [
{
"_index" : "posts",
"_type" : "doc",
"_id" : "1733768",
"_score" : 1.0,
"_source" : {
"doc" : {
"id" : 1733768,
"description" : "",
"ext" : "png",
"tags" : [],
...
}
}
}
]
},
"aggregations" : {
"min_id" : {
"value" : null
}
}
}

我究竟做错了什么?

最佳答案

差不多了,您犯了一个小错误,id字段位于doc对象结构内部,因此您需要查询doc.id而不是id,如下所示:

POST /posts/_search?size=0
{
"aggs" : {
"min_id" : { "min" : { "field" : "doc.id" } }
^
|
add this
}
}

关于elasticsearch - Elasticsearch Minimum Aggreviate返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53905189/

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