【发布时间】:2015-02-11 13:58:05
【问题描述】:
我将网站的每个页面视图保存在 ES 索引中,其中每个页面都由 entity_id 识别。 我需要获取自给定时间点以来的 unique 页面查看总数。 我有以下映射:
{
"my_index": {
"mappings": {
"page_views": {
"_all": {
"enabled": true
},
"properties": {
"created": {
"type": "long"
},
"entity_id": {
"type": "integer"
}
}
}
}
}
}
根据 Elasticsearch 文档,这样做的方法是使用基数聚合。 这是我的搜索请求:
GET my_index/page_views/_search
{
"filter": {
"bool": {
"must": [
[
{
"range": {
"created": {
"gte": 9999999999
}
}
}
]
]
}
},
"aggs": {
"distinct_entities": {
"cardinality": {
"field": "entity_id",
"precision_threshold": 100
}
}
}
}
请注意,我在未来使用了时间戳,因此不会返回任何结果。 我得到的结果是:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
},
"aggregations": {
"distinct_entities": {
"value": 116
}
}
}
我不明白唯一页面访问量为何会达到 116,因为搜索查询根本没有页面访问量。我做错了什么?
【问题讨论】:
标签: elasticsearch aggregation cardinality