赞
踩
GET http://ip:prot/textbook/_search
{ "query" : { ...query子句... },
"aggs" : {
"agg_name":{
"agg_type": {
"agg_arg": agg_arg_value
}
}
},
"sort" : { ..sort子句.. }
"from" : 0, // 返回搜索结果的开始位置
"size" : 10, // 分页大小,一次返回多少数据
"_source" :[ ...需要返回的字段数组... ],
}
这个聚合查询就是写aggs里面的语句。其中,agg_name
是聚合操作的名称,agg_type
是聚合操作的类型,agg_arg
是聚合操作的参数,agg_arg_value
是参数值。
这个查询将返回"amount"字段的平均值。在聚合查询中,"size"参数设置为0,表示不需要返回文档本身,只需要聚合结果。下面的这个只是一个简单的查询,是单值分析。
- Get /my_index/_search
- {
- "size": 0,
- "aggs": {
- //求amount字段的平均值
- "amount_avg": {
- "avg": {
- "field": "amount"
- },
- //求amount字段的最小值
- "min_sales": {
- "min": {
- "field": "amount"
- }
- },
- //求amount字段的最大值
- "my_max":{
- "max": {
- "field":"amount"
- }
- }
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
_stats
查询来获取有关字段的统计信息,例如平均值、最小值、最大值等。- Get /my_index/_search
- {
- "size": 0,
- "aggs": {
- //求amount字段的各个指标
- "my_stats": {
- "stats": {
- "field": "amount"
- }
- }
- }
_extended_stats
查询来获取有关字段的扩展统计信息,例如方差、偏度和峰度。 - GET /your_index/_search
- {
- "size": 0,
- "aggs": {
- "my_extended_stats": {
- "extended_stats": {
- "field": "amount"
- }
- }
- }
- }
- GET /your_index/_search
- {
- "size": 0,
- "aggs": {
- "my_cardinality": {
- "cardinality": {
- "field": "amount"
- }
- }
- }
- }
- GET /your_index/_search
- {
- "size": 0,
- "aggs": {
- "my_percentiles": {
- "percentiles": {
- "field": "amount",
- "percents": [
- 20,
- 50,
- 75,
- 99
- ]
- }
- }
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- GET /your_index/_search
- {
- "size": 0,
- "aggs": {
- "My_top": {
- "top_hits": {
- "_source": ["aaaa"],
- "size": 2
- }
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。