【发布时间】:2016-02-06 18:21:58
【问题描述】:
仅供参考,我在 Mac 中使用 ES 1.7.2。
我一直在尝试获取结果集的聚合,但我得到的是所有记录的聚合。
假设我想退回 200 辆福特福克斯 SE 车辆,从这 200 辆汽车中,我想知道所有这些车辆的内饰以及每个内饰有多少辆车。所以基本上计算了那些修剪,但也得到了 200 个结果。
这是我目前所拥有的(我正在使用 Sense/Marvel...更容易测试):
GET jdbc/_search
{
"size": 200,
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{ "term": { "listing.model": "Focus" }},
{ "term": { "listing.make": "Ford" }}
]
}
}
}
},
"aggs": {
"trims": {
"terms": { "field": "listing.trim" }
},
"trim_SE": {
"filter": {
"term": { "listing.trim": "SE" }
},
"aggs": {
"trims": {
"terms": { "field": "listing.trim"}
}
}
}
},
"post_filter": {
"term": { "listing.trim": "SE" }
}
}
所以我确实得到了 20 个结果,如下所示:
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10338,
"max_score": 1,
"hits": [
{
"_index": "myindex",
"_type": "mytype",
"_id": "472",
"_score": 1,
"_source": {
"listing": {
"vin": "111111111111",
"year": 2013,
"make": "Ford",
"model": "Focus",
"trim": "SE",
}
}
},
{...}
]
}
"aggregations": {
"trims": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 30,
"buckets": [
{
"key": "SE",
"doc_count": 10338
},
{
"key": "SEL",
"doc_count": 1000
},
{
"key": "Titanium",
"doc_count": 874
},
{
"key": "SES",
"doc_count": 585
},
{
"key": "S",
"doc_count": 554
},
{
"key": "",
"doc_count": 447
},
{
"key": "ST",
"doc_count": 339
},
{
"key": "ZTS",
"doc_count": 60
},
{
"key": "LX",
"doc_count": 56
},
{
"key": "Electric",
"doc_count": 18
}
]
},
"trim_SE": {
"doc_count": 10338,
"trims": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "SE",
"doc_count": 10338
}
]
}
}
}
}
但正如您所见,Trims 显示的计数比 200 多,这意味着它正在对所有车辆进行聚合。
我需要一些帮助,但我找不到任何能真正使这项工作正常进行的东西。
提前感谢您的帮助!
【问题讨论】:
-
以后不要犹豫,使用found.no/play创建一个可复制的案例。这是分享弹性搜索问题的最佳工具。
-
超级有趣的工具!感谢分享!我一定会仔细看看。
标签: search lucene search-engine elasticsearch