我有这样的结构索引
...
user_id => [
type => keyword
],
geo => [
type => nested
city => [
type => keyword
]
...
]
...
我想获取按www.example.com分组的不同用户geo.city
SQL
select
geo.city as user_city, count(distinct user_id) as users
from
`table`
group by
user_city
order by
users desc
count total返回的是ok,但不是唯一的user_id我尝试这个但count by user_id是0
'aggs' => [
'nested_geo' => [
'nested' => [
'path' => 'geo',
],
'aggs' => [
'group_by_city' => [
'terms' => [
'field' => 'geo.city',
],
'aggs' => [
'distinct_users' => [
'cardinality' => [
'field' => 'user_id',
],
],
],
],
],
],
],
1条答案
按热度按时间dpiehjr41#
使用' reverse_nested '解决