Ruby on rails Searchkick聚合行为
我正在使用Searchkick Gem和弹性搜索,并试图了解聚合行为 我有三个方面(聚合):城市、州和公司 如果按其中任何一个进行过滤,则其他两个的计数将减少,以反映结果集中的总数。但是所选的方面会返回所有值。假设我在索引中有100个项目,我通过一家公司筛选,该公司在索引中有2个项目,城市和州的计数会更新,以反映不超过2个项目。但该公司的数字仍为100 示例(过滤到城市=亚特兰大) 结果(返回2个结果,但返回58个城市聚合)。注意:公司和城市返回正确的聚合值:Ruby on rails Searchkick聚合行为,ruby-on-rails,
elasticsearch,searchkick,Ruby On Rails,
elasticsearch,Searchkick,我正在使用Searchkick Gem和弹性搜索,并试图了解聚合行为 我有三个方面(聚合):城市、州和公司 如果按其中任何一个进行过滤,则其他两个的计数将减少,以反映结果集中的总数。但是所选的方面会返回所有值。假设我在索引中有100个项目,我通过一家公司筛选,该公司在索引中有2个项目,城市和州的计数会更新,以反映不超过2个项目。但该公司的数字仍为100 示例(过滤到城市=亚特兰大) 结果(返回2个结果,但返回58个城市聚合)。注意:公司和城市返回正确的聚合值: { "took": 114,
{
"took": 114,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "jobs_development_20160818140128648",
"_type": "job",
"_id": "457134",
"_score": 1
},
{
"_index": "jobs_development_20160818140128648",
"_type": "job",
"_id": "457137",
"_score": 1
}
]
},
"aggregations": {
"city": {
"doc_count": 58,
"city": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 19,
"buckets": [
{
"key": "Los Angeles",
"doc_count": 8
},
{
"key": "London",
"doc_count": 7
},
{
"key": "New York",
"doc_count": 7
},
{
"key": "Burbank",
"doc_count": 5
},
{
"key": "Pasig",
"doc_count": 3
},
{
"key": "Atlanta",
"doc_count": 2
},
{
"key": "Chicago",
"doc_count": 2
},
{
"key": "Culver City",
"doc_count": 2
},
{
"key": "London Borough of Hackney",
"doc_count": 2
},
{
"key": "Birmingham",
"doc_count": 1
}
]
}
},
"company": {
"doc_count": 2,
"company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Second Story",
"doc_count": 2
}
]
}
},
"state": {
"doc_count": 2,
"state": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Georgia",
"doc_count": 2
}
]
}
}
}
}
我错过了什么?这是正确的行为吗?虽然您的查询可以进一步优化,但在我看来,查询和响应是正确的。这通常是多类别面的行为方式。你还期待什么吗?谢谢@bittusarkar,我希望结果最多只能返回2个城市,因为只有2个结果。相反,它会返回58?,这应该是正确的。想一想。您已经在
“Atlanta”
城市上进行了筛选,因此在您期望的结果中,您只需获得“Atlanta”->2
。我认为那没有多大用处。但是,如果您希望这样做,只需在city
聚合中添加city
过滤器,就像您在其他两个聚合中添加过滤器一样。虽然您的查询可以进一步优化,但查询和响应在我看来是正确的。这通常是多类别面的行为方式。你还期待什么吗?谢谢@bittusarkar,我希望结果最多只能返回2个城市,因为只有2个结果。相反,它会返回58?,这应该是正确的。想一想。您已经在“Atlanta”
城市上进行了筛选,因此在您期望的结果中,您只需获得“Atlanta”->2
。我认为那没有多大用处。但是,如果您想这样做,只需在city
聚合中添加city
过滤器,就像在其他两个聚合中添加过滤器一样。
{
"took": 114,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "jobs_development_20160818140128648",
"_type": "job",
"_id": "457134",
"_score": 1
},
{
"_index": "jobs_development_20160818140128648",
"_type": "job",
"_id": "457137",
"_score": 1
}
]
},
"aggregations": {
"city": {
"doc_count": 58,
"city": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 19,
"buckets": [
{
"key": "Los Angeles",
"doc_count": 8
},
{
"key": "London",
"doc_count": 7
},
{
"key": "New York",
"doc_count": 7
},
{
"key": "Burbank",
"doc_count": 5
},
{
"key": "Pasig",
"doc_count": 3
},
{
"key": "Atlanta",
"doc_count": 2
},
{
"key": "Chicago",
"doc_count": 2
},
{
"key": "Culver City",
"doc_count": 2
},
{
"key": "London Borough of Hackney",
"doc_count": 2
},
{
"key": "Birmingham",
"doc_count": 1
}
]
}
},
"company": {
"doc_count": 2,
"company": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Second Story",
"doc_count": 2
}
]
}
},
"state": {
"doc_count": 2,
"state": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Georgia",
"doc_count": 2
}
]
}
}
}
}