用户聚合数量查询
$params = [
'index' => ES::USER_ACTION_RECORD_LOGS,
'type' => '_doc',
'body' => [
'query' => [
'bool' => [
'filter' => [
[
'term' => [
'activity_id' => $activityId
],
]
]
]
],
'size'=>0,
"aggs"=>[
"user_count"=>[
"cardinality"=>[
"field"=>"user_id.keyword"
]
]
]
]
];
时间区间uv查询
$params = [
'index' => ES::APPLICATION_LOGS,
'type' => '_doc',
'body' => [
'query' => [
'bool' => [
'filter' => [
[
'term' => [
'ActivityId' => $activityId
],
],
[
'range' => [
'CreatedAt' => [
'gte' => $startTime,
'lt' => $endTime,
"format"=>"yyyy-MM-dd HH:mm:ss"
]
]
]
]
]
],
'size'=>0,
'aggs'=>[
"list"=>[
"date_histogram"=>[
"min_doc_count"=>0,
"field"=>"CreatedAt",
"interval"=>"30m",
"format"=>"yyyy-MM-dd HH:mm:ss"
],
"aggs"=>[
"user_count"=>[
"cardinality"=>[
"field"=>"UserUniqueId.keyword"
]
]
]
]
]
]
];