尝试使用以下类型的 ElasticSearch 日志构建日期直方图:
{
"_index": "foo"
"_source": {
[…]
"time": "2013-06-12T14:43:13.238-07:00",
"userName": "bar"
}
}
其中直方图按“天”间隔存储“时间”字段,但也仅将单个用户名的多次出现计算一次。
我尝试了以下方法:
{
"query" : {
"match_all" : {}
},
"facets" : {
"histo1" : {
"date_histogram" : {
"key_field" : "time",
"value_script" : "doc['userName'].values.length",
"interval" : "day"
}
}
}
}
我预计每个“histo1”条目的最小值|最大值|平均值是各个时间段中唯一用户的数量。但结果始终如一地返回min = max = mean = 1
"histo1": {
"_type": "date_histogram",
"entries": [
{
"time": 1370908800000,
"count": 11,
"min": 1,
"max": 1,
"total": 11,
"total_count": 11,
"mean": 1
},
{
"time": 1370995200000,
"count": 18,
"min": 1,
"max": 1,
"total": 18,
"total_count": 18,
"mean": 1
}
]
}
我是否误解了键/值在日期直方图中的工作方式?