一、基礎數據
GET /my-index/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "my-index",
"_type": "person",
"_id": "5",
"_score": 1,
"_source": {
"name": "kobe",
"age": 28,
"salary": 10000
}
},
{
"_index": "my-index",
"_type": "person",
"_id": "6",
"_score": 1,
"_source": {
"name": "hadron",
"age": 19,
"salary": 5000
}
}
]
}
}
二、max
GET /my-index/_search
{
"size": 1,
"aggs": {
"max_age": {
"max": {
"field": "age"
}
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "my-index",
"_type": "person",
"_id": "5",
"_score": 1,
"_source": {
"name": "kobe",
"age": 28,
"salary": 10000
}
}
]
},
"aggregations": {
"max_age": {
"value": 28
}
}
}
三、min
GET /my-index/_search
{
"size": 2,
"aggs": {
"min_age": {
"min": {
"field": "age"
}
}
}
}
四、avg
GET /my-index/_search
{
"size": 2,
"aggs": {
"avg_age": {
"avg": {
"field": "age"
}
}
}
}
五、sum
GET /my-index/_search
{
"size": 20,
"aggs": {
"sum_salary": {
"sum": {
"field": "salary"
}
}
}
}
六、 stat
GET my-index/_search
{
"size": 0,
"aggs": {
"stats_salary": {
"stats": {"field": "salary"}
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"stats_salary": {
"count": 2,
"min": 5000,
"max": 10000,
"avg": 7500,
"sum": 15000
}
}
}
七、高級統計
GET my-index/_search
{
"size": 0,
"aggs": {
"stats_salary": {
"extended_stats": {"field": "salary"}
}
}
}
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"stats_salary": {
"count": 2,
"min": 5000,
"max": 10000,
"avg": 7500,
"sum": 15000,
"sum_of_squares": 125000000,
"variance": 6250000,
"std_deviation": 2500,
"std_deviation_bounds": {
"upper": 12500,
"lower": 2500
}
}
}
}
八、文檔數量統計
GET my-index/_search
{
"size": 0,
"aggs": {
"doc_count": {
"value_count": {"field": "salary"}
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0,
"hits": []
},
"aggregations": {
"doc_count": {
"value": 2
}
}
}
九、百分位統計
GET my-index/_search
{
"size": 0,
"aggs": {
"persion_salary": {
"percentiles": {"field": "salary"}
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0,
"hits": []
},
"aggregations": {
"persion_salary": {
"values": {
"1.0": 5000,
"5.0": 5000,
"25.0": 5000,
"50.0": 7500,
"75.0": 10000,
"95.0": 10000,
"99.0": 10000
}
}
}
}