POST /cars/_bulk
{ “index”: {}}
{ “价格” : 10000, “颜色” : “red”, “品牌” : “honda”, “售出时间” : “2014-10-28” }
{ “index”: {}}
{ “价格” : 20000, “颜色” : “red”, “品牌” : “honda”, “售出时间” : “2014-11-05” }
{ “index”: {}}
{ “价格” : 30000, “颜色” : “green”, “品牌” : “ford”, “售出时间” : “2014-05-18” }
{ “index”: {}}
{ “价格” : 15000, “颜色” : “blue”, “品牌” : “toyota”, “售出时间” : “2014-07-02” }
{ “index”: {}}
{ “价格” : 12000, “颜色” : “green”, “品牌” : “toyota”, “售出时间” : “2014-08-19” }
{ “index”: {}}
{ “价格” : 20000, “颜色” : “red”, “品牌” : “honda”, “售出时间” : “2014-11-05” }
{ “index”: {}}
{ “价格” : 80000, “颜色” : “red”, “品牌” : “bmw”, “售出时间” : “2014-01-01” }
{ “index”: {}}
{ “价格” : 25000, “颜色” : “blue”, “品牌” : “ford”, “售出时间” : “2014-02-12” }
GET /cars/_search
{
"aggs": {
"分组名": {
"terms": {
"field": "颜色"
},
"aggs": {
"平均值": {
"avg": {
"field": "价格"
}
},
"计数": {
"terms": {
"field": "品牌"
}
}
}
}
}
}
### 按照颜色字段分组统计,求价格的分组平均值,和分组后的区域计数
###
avg 平均
max 最大
min 最小
sum 合计
terms 计数
###以每隔5000的价格进行自动分段
GET /cars/_search
{
"size": 0,
"aggs": {
"price_histogram": {
"histogram": {
"field": "价格",
"interval": 5000,
"min_doc_count": 1
}
}
}
}
GET /cars/_search
{
"size": 0,
"aggs": {
"price_range": {
"range": {
"field": "价格",
"ranges": [
{
"from": 5000,
"to": 15000
},
{
"from": 15000,
"to": 17000
},
{
"from": 17000,
"to": 25000
},
{
"from": 25000,
"to": 39000
},
{
"from": 39000
}
]
}
}
}
}