我正在使用术语聚合来获取每个城市的所有用户
$oSetting = PersonalSetting::find($id);
$oSetting->Login = utf8_decode($login);
$oSetting->Sign = utf8_decode($sign);
$oSetting->save();
这是结果。但我总是希望得到一些特定城市的聚合结果,无论他们是否排在前10名。我是否需要分别对每个城市使用过滤器聚合来获得结果?
答案 0 :(得分:0)
您有三种解决方案:
一个。您可以在查询中指定过滤器:
{
"query": {
"terms": {
"city.name": [ "city1", "city2", "city3" ]
}
},
"aggs": {
"cities": {
"terms": {
"field": "city.name"
}
}
}
}
B中。您可以在聚合中指定过滤器:
{
"aggs": {
"city_filter": {
"filter": {
"terms": {
"city.name": [
"city1",
"city2",
"city3"
]
}
},
"aggs": {
"cities": {
"terms": {
"field": "city.name"
}
}
}
}
}
}
℃。您可以在聚合:
这两个词中filter values{
"aggs": {
"cities": {
"terms": {
"field": "city.name",
"include": "city1*",
"exclude": "city2*"
}
}
}
}