我有一个叫做“posts”的elasticsearch索引。 http://127.0.0.1:9200/posts/doc/_count
退货 {"count":240000,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0}}
.
我试图在类型“doc”中找到最低的id字段。经过谷歌搜索,我相信我想要的工具是聚合。
主要是直接从官方文件中复制和粘贴,我开始使用以下内容:
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
不应为空。
当我搜索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
}
}
}
我做错什么了?
1条答案
按热度按时间8zzbczxx1#
你就快到了,你只是犯了个小错误
id
字段位于doc
对象结构,因此需要查询doc.id
而不仅仅是id
,如下所示: