前端最终效果展示
- 这里需要统计不同年龄段的人数,以10为间隔
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56"age_ranges": {
"range": {
"field": "VISIT_AGE",
"ranges": [{
"key": "0-10",
"from": 0,
"to": 10
},
{
"key": "10-20",
"from": 10,
"to": 20
},
{
"key": "20-30",
"from": 20,
"to": 30
},
{
"key": "30-40",
"from": 30,
"to": 40
},
{
"key": "40-50",
"from": 40,
"to": 50
},
{
"key": "50-60",
"from": 50,
"to": 60
},
{
"key": "60-70",
"from": 60,
"to": 70
},
{
"key": "70-80",
"from": 70,
"to": 80
},
{
"key": "80-90",
"from": 80,
"to": 90
},
{
"key": "90-100",
"from": 90,
"to": 100
}
]
}
}
查询语句中一开始ranges没有key键,只有{“”from”: 0,”to”: 10”},这样查询的结果会转成浮点数,如下
1 | {'buckets': [{'key': '0.0-10.0', 'from': 0.0, 'to': 10.0, 'doc_count': 0}, {'key': '10.0-20.0', 'from': 10.0, 'to': 20.0, 'doc_count': 0}, {'key': '21.0-30.0', 'from': 21.0, 'to': 30.0, 'doc_count': 1}, {'key': '31.0-40.0', 'from': 31.0, 'to': 40.0, 'doc_count': 4}, {'key': '41.0-50.0', 'from': 41.0, 'to': 50.0, 'doc_count': 5}, {'key': '51.0-60.0', 'from': 51.0, 'to': 60.0, 'doc_count': 16}, {'key': '61.0-70.0', 'from': 61.0, 'to': 70.0, 'doc_count': 29}, {'key': '71.0-80.0', 'from': 71.0, 'to': 80.0, 'doc_count': 12}, {'key': '80.0-90.0', 'from': 80.0, 'to': 90.0, 'doc_count': 3}, {'key': '91.0-100.0', 'from': 91.0, 'to': 100.0, 'doc_count': 0}]} |
加上key就可以指定返回的key了