Dev*_*per 11 facet aggregation elasticsearch
我正在学习弹性搜索,并希望计算不同的值.到目前为止,我可以计算值,但不是很明显.
以下是示例数据:
curl http://localhost:9200/store/item/ -XPOST -d '{
"RestaurantId": 2,
"RestaurantName": "Restaurant Brian",
"DateTime": "2013-08-16T15:13:47.4833748+01:00"
}'
curl http://localhost:9200/store/item/ -XPOST -d '{
"RestaurantId": 1,
"RestaurantName": "Restaurant Cecil",
"DateTime": "2013-08-16T15:13:47.4833748+01:00"
}'
curl http://localhost:9200/store/item/ -XPOST -d '{
"RestaurantId": 1,
"RestaurantName": "Restaurant Cecil",
"DateTime": "2013-08-16T15:13:47.4833748+01:00"
}'
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试了什么:
curl -XPOST "http://localhost:9200/store/item/_search" -d '{
"size": 0,
"aggs": {
"item": {
"terms": {
"field": "RestaurantName"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
输出:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"item": {
"buckets": [
{
"key": "restaurant",
"doc_count": 3
},
{
"key": "cecil",
"doc_count": 2
},
{
"key": "brian",
"doc_count": 1
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何计算cecil为1而不是2
您必须使用@coder提到的基数选项,您可以在文档中找到该选项
$ curl -XGET "http://localhost:9200/store/item/_search" -d'
{
"aggs" : {
"restaurant_count" : {
"cardinality" : {
"field" : "RestaurantName",
"precision_threshold": 100,
"rehash": false
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
这对我有用......
| 归档时间: |
|
| 查看次数: |
22390 次 |
| 最近记录: |