##按照年龄分布和性别区分查出平均薪资 GET bank/_search { "query": {"match_all": {}}, "aggs": { "ageAgg": { "terms": { "field": "age", "size": 100 }, "aggs": { "genderAgg": { "terms": { "field": "gender.keyword" }, "aggs": { "balanceAgg": { "avg": { "field": "balance" } } } }, "ageBalanceAvg" : { "avg": { "field": "balance" } } } } }, "size":0 }
##按照年龄分布和性别区分查出平均薪资
GET bank/_search
{
"query": {"match_all": {}},
"aggs": {
"ageAgg": {
"terms": {
"field": "age",
"size": 100
},
"aggs": {
"genderAgg": {
"terms": {
"field": "gender.keyword"
},
"aggs": {
"balanceAgg": {
"avg": {
"field": "balance"
}
}
}
},
"ageBalanceAvg" : {
"avg": {
"field": "balance"
}
}
}
}
},
"size":0
}
{ "took" : 28, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1000, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "aggregations" : { "ageAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : 31, "doc_count" : 61, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 35, "balanceAgg" : { "value" : 29565.628571428573 } }, { "key" : "F", "doc_count" : 26, "balanceAgg" : { "value" : 26626.576923076922 } } ] }, "ageBalanceAvg" : { "value" : 28312.918032786885 } }, { "key" : 39, "doc_count" : 60, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 38, "balanceAgg" : { "value" : 26348.684210526317 } }, { "key" : "M", "doc_count" : 22, "balanceAgg" : { "value" : 23405.68181818182 } } ] }, "ageBalanceAvg" : { "value" : 25269.583333333332 } }, { "key" : 26, "doc_count" : 59, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 32, "balanceAgg" : { "value" : 25094.78125 } }, { "key" : "F", "doc_count" : 27, "balanceAgg" : { "value" : 20943.0 } } ] }, "ageBalanceAvg" : { "value" : 23194.813559322032 } }, { "key" : 32, "doc_count" : 52, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 28, "balanceAgg" : { "value" : 22941.964285714286 } }, { "key" : "F", "doc_count" : 24, "balanceAgg" : { "value" : 25128.958333333332 } } ] }, "ageBalanceAvg" : { "value" : 23951.346153846152 } }, { "key" : 35, "doc_count" : 52, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 28, "balanceAgg" : { "value" : 24226.321428571428 } }, { "key" : "F", "doc_count" : 24, "balanceAgg" : { "value" : 19698.791666666668 } } ] }, "ageBalanceAvg" : { "value" : 22136.69230769231 } }, { "key" : 36, "doc_count" : 52, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 31, "balanceAgg" : { "value" : 20884.677419354837 } }, { "key" : "F", "doc_count" : 21, "balanceAgg" : { "value" : 24079.04761904762 } } ] }, "ageBalanceAvg" : { "value" : 22174.71153846154 } }, { "key" : 22, "doc_count" : 51, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 27, "balanceAgg" : { "value" : 22152.74074074074 } }, { "key" : "M", "doc_count" : 24, "balanceAgg" : { "value" : 27631.708333333332 } } ] }, "ageBalanceAvg" : { "value" : 24731.07843137255 } }, { "key" : 28, "doc_count" : 51, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 31, "balanceAgg" : { "value" : 27076.8064516129 } }, { "key" : "M", "doc_count" : 20, "balanceAgg" : { "value" : 30129.35 } } ] }, "ageBalanceAvg" : { "value" : 28273.882352941175 } }, { "key" : 33, "doc_count" : 50, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 26, "balanceAgg" : { "value" : 26437.615384615383 } }, { "key" : "M", "doc_count" : 24, "balanceAgg" : { "value" : 23638.291666666668 } } ] }, "ageBalanceAvg" : { "value" : 25093.94 } }, { "key" : 34, "doc_count" : 49, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 30, "balanceAgg" : { "value" : 26039.166666666668 } }, { "key" : "M", "doc_count" : 19, "balanceAgg" : { "value" : 28027.0 } } ] }, "ageBalanceAvg" : { "value" : 26809.95918367347 } }, { "key" : 30, "doc_count" : 47, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 25, "balanceAgg" : { "value" : 25316.16 } }, { "key" : "M", "doc_count" : 22, "balanceAgg" : { "value" : 20028.545454545456 } } ] }, "ageBalanceAvg" : { "value" : 22841.106382978724 } }, { "key" : 21, "doc_count" : 46, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 24, "balanceAgg" : { "value" : 28210.916666666668 } }, { "key" : "M", "doc_count" : 22, "balanceAgg" : { "value" : 25640.18181818182 } } ] }, "ageBalanceAvg" : { "value" : 26981.434782608696 } }, { "key" : 40, "doc_count" : 45, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 24, "balanceAgg" : { "value" : 26474.958333333332 } }, { "key" : "F", "doc_count" : 21, "balanceAgg" : { "value" : 27992.571428571428 } } ] }, "ageBalanceAvg" : { "value" : 27183.17777777778 } }, { "key" : 20, "doc_count" : 44, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 27, "balanceAgg" : { "value" : 29047.444444444445 } }, { "key" : "F", "doc_count" : 17, "balanceAgg" : { "value" : 25666.647058823528 } } ] }, "ageBalanceAvg" : { "value" : 27741.227272727272 } }, { "key" : 23, "doc_count" : 42, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 24, "balanceAgg" : { "value" : 27730.75 } }, { "key" : "F", "doc_count" : 18, "balanceAgg" : { "value" : 26758.833333333332 } } ] }, "ageBalanceAvg" : { "value" : 27314.214285714286 } }, { "key" : 24, "doc_count" : 42, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 23, "balanceAgg" : { "value" : 29414.521739130436 } }, { "key" : "M", "doc_count" : 19, "balanceAgg" : { "value" : 27435.052631578947 } } ] }, "ageBalanceAvg" : { "value" : 28519.04761904762 } }, { "key" : 25, "doc_count" : 42, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 23, "balanceAgg" : { "value" : 29336.08695652174 } }, { "key" : "F", "doc_count" : 19, "balanceAgg" : { "value" : 25156.263157894737 } } ] }, "ageBalanceAvg" : { "value" : 27445.214285714286 } }, { "key" : 37, "doc_count" : 42, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 23, "balanceAgg" : { "value" : 25015.739130434784 } }, { "key" : "F", "doc_count" : 19, "balanceAgg" : { "value" : 29451.21052631579 } } ] }, "ageBalanceAvg" : { "value" : 27022.261904761905 } }, { "key" : 27, "doc_count" : 39, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 21, "balanceAgg" : { "value" : 21618.85714285714 } }, { "key" : "M", "doc_count" : 18, "balanceAgg" : { "value" : 21300.38888888889 } } ] }, "ageBalanceAvg" : { "value" : 21471.871794871793 } }, { "key" : 38, "doc_count" : 39, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "F", "doc_count" : 20, "balanceAgg" : { "value" : 27931.65 } }, { "key" : "M", "doc_count" : 19, "balanceAgg" : { "value" : 24350.894736842107 } } ] }, "ageBalanceAvg" : { "value" : 26187.17948717949 } }, { "key" : 29, "doc_count" : 35, "genderAgg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "M", "doc_count" : 23, "balanceAgg" : { "value" : 29943.17391304348 } }, { "key" : "F", "doc_count" : 12, "balanceAgg" : { "value" : 28601.416666666668 } } ] }, "ageBalanceAvg" : { "value" : 29483.14285714286 } } ] } } }
{
"took" : 28,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1000,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"ageAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 31,
"doc_count" : 61,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 35,
"balanceAgg" : {
"value" : 29565.628571428573
}
},
{
"key" : "F",
"doc_count" : 26,
"balanceAgg" : {
"value" : 26626.576923076922
}
}
]
},
"ageBalanceAvg" : {
"value" : 28312.918032786885
}
},
{
"key" : 39,
"doc_count" : 60,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 38,
"balanceAgg" : {
"value" : 26348.684210526317
}
},
{
"key" : "M",
"doc_count" : 22,
"balanceAgg" : {
"value" : 23405.68181818182
}
}
]
},
"ageBalanceAvg" : {
"value" : 25269.583333333332
}
},
{
"key" : 26,
"doc_count" : 59,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 32,
"balanceAgg" : {
"value" : 25094.78125
}
},
{
"key" : "F",
"doc_count" : 27,
"balanceAgg" : {
"value" : 20943.0
}
}
]
},
"ageBalanceAvg" : {
"value" : 23194.813559322032
}
},
{
"key" : 32,
"doc_count" : 52,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 28,
"balanceAgg" : {
"value" : 22941.964285714286
}
},
{
"key" : "F",
"doc_count" : 24,
"balanceAgg" : {
"value" : 25128.958333333332
}
}
]
},
"ageBalanceAvg" : {
"value" : 23951.346153846152
}
},
{
"key" : 35,
"doc_count" : 52,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 28,
"balanceAgg" : {
"value" : 24226.321428571428
}
},
{
"key" : "F",
"doc_count" : 24,
"balanceAgg" : {
"value" : 19698.791666666668
}
}
]
},
"ageBalanceAvg" : {
"value" : 22136.69230769231
}
},
{
"key" : 36,
"doc_count" : 52,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 31,
"balanceAgg" : {
"value" : 20884.677419354837
}
},
{
"key" : "F",
"doc_count" : 21,
"balanceAgg" : {
"value" : 24079.04761904762
}
}
]
},
"ageBalanceAvg" : {
"value" : 22174.71153846154
}
},
{
"key" : 22,
"doc_count" : 51,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 27,
"balanceAgg" : {
"value" : 22152.74074074074
}
},
{
"key" : "M",
"doc_count" : 24,
"balanceAgg" : {
"value" : 27631.708333333332
}
}
]
},
"ageBalanceAvg" : {
"value" : 24731.07843137255
}
},
{
"key" : 28,
"doc_count" : 51,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 31,
"balanceAgg" : {
"value" : 27076.8064516129
}
},
{
"key" : "M",
"doc_count" : 20,
"balanceAgg" : {
"value" : 30129.35
}
}
]
},
"ageBalanceAvg" : {
"value" : 28273.882352941175
}
},
{
"key" : 33,
"doc_count" : 50,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 26,
"balanceAgg" : {
"value" : 26437.615384615383
}
},
{
"key" : "M",
"doc_count" : 24,
"balanceAgg" : {
"value" : 23638.291666666668
}
}
]
},
"ageBalanceAvg" : {
"value" : 25093.94
}
},
{
"key" : 34,
"doc_count" : 49,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 30,
"balanceAgg" : {
"value" : 26039.166666666668
}
},
{
"key" : "M",
"doc_count" : 19,
"balanceAgg" : {
"value" : 28027.0
}
}
]
},
"ageBalanceAvg" : {
"value" : 26809.95918367347
}
},
{
"key" : 30,
"doc_count" : 47,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 25,
"balanceAgg" : {
"value" : 25316.16
}
},
{
"key" : "M",
"doc_count" : 22,
"balanceAgg" : {
"value" : 20028.545454545456
}
}
]
},
"ageBalanceAvg" : {
"value" : 22841.106382978724
}
},
{
"key" : 21,
"doc_count" : 46,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 24,
"balanceAgg" : {
"value" : 28210.916666666668
}
},
{
"key" : "M",
"doc_count" : 22,
"balanceAgg" : {
"value" : 25640.18181818182
}
}
]
},
"ageBalanceAvg" : {
"value" : 26981.434782608696
}
},
{
"key" : 40,
"doc_count" : 45,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 24,
"balanceAgg" : {
"value" : 26474.958333333332
}
},
{
"key" : "F",
"doc_count" : 21,
"balanceAgg" : {
"value" : 27992.571428571428
}
}
]
},
"ageBalanceAvg" : {
"value" : 27183.17777777778
}
},
{
"key" : 20,
"doc_count" : 44,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 27,
"balanceAgg" : {
"value" : 29047.444444444445
}
},
{
"key" : "F",
"doc_count" : 17,
"balanceAgg" : {
"value" : 25666.647058823528
}
}
]
},
"ageBalanceAvg" : {
"value" : 27741.227272727272
}
},
{
"key" : 23,
"doc_count" : 42,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 24,
"balanceAgg" : {
"value" : 27730.75
}
},
{
"key" : "F",
"doc_count" : 18,
"balanceAgg" : {
"value" : 26758.833333333332
}
}
]
},
"ageBalanceAvg" : {
"value" : 27314.214285714286
}
},
{
"key" : 24,
"doc_count" : 42,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 23,
"balanceAgg" : {
"value" : 29414.521739130436
}
},
{
"key" : "M",
"doc_count" : 19,
"balanceAgg" : {
"value" : 27435.052631578947
}
}
]
},
"ageBalanceAvg" : {
"value" : 28519.04761904762
}
},
{
"key" : 25,
"doc_count" : 42,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 23,
"balanceAgg" : {
"value" : 29336.08695652174
}
},
{
"key" : "F",
"doc_count" : 19,
"balanceAgg" : {
"value" : 25156.263157894737
}
}
]
},
"ageBalanceAvg" : {
"value" : 27445.214285714286
}
},
{
"key" : 37,
"doc_count" : 42,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 23,
"balanceAgg" : {
"value" : 25015.739130434784
}
},
{
"key" : "F",
"doc_count" : 19,
"balanceAgg" : {
"value" : 29451.21052631579
}
}
]
},
"ageBalanceAvg" : {
"value" : 27022.261904761905
}
},
{
"key" : 27,
"doc_count" : 39,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 21,
"balanceAgg" : {
"value" : 21618.85714285714
}
},
{
"key" : "M",
"doc_count" : 18,
"balanceAgg" : {
"value" : 21300.38888888889
}
}
]
},
"ageBalanceAvg" : {
"value" : 21471.871794871793
}
},
{
"key" : 38,
"doc_count" : 39,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "F",
"doc_count" : 20,
"balanceAgg" : {
"value" : 27931.65
}
},
{
"key" : "M",
"doc_count" : 19,
"balanceAgg" : {
"value" : 24350.894736842107
}
}
]
},
"ageBalanceAvg" : {
"value" : 26187.17948717949
}
},
{
"key" : 29,
"doc_count" : 35,
"genderAgg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "M",
"doc_count" : 23,
"balanceAgg" : {
"value" : 29943.17391304348
}
},
{
"key" : "F",
"doc_count" : 12,
"balanceAgg" : {
"value" : 28601.416666666668
}
}
]
},
"ageBalanceAvg" : {
"value" : 29483.14285714286
}
}
]
}
}
}