GET /mybooks/_search
{
"query": {
"bool": {
"must": [
{
"prefix": {
"region_id": "11"
}
}
]
}
},
"aggs": {
"group_location": {
"terms": {
"script": {
"source": "boolean b = doc['region_id'].size() > 0;String c = doc['region_id'].value;if (b && c.length() > 2){return c.substring(0, 2)}"
},
"size": 6
},
"aggs": {
"group_ent": {
"terms": {
"field": "_id",
"size": 6,
"order": {
"nest>total": "desc"
}
},
"aggs": {
"nest": {
"nested": {
"path": "info"
},
"aggs": {
"total": {
"sum": {
"field": "info.money"
}
}
}
}
}
}
}
}
},
"from": 0,
"size": 0
}