I would like to categorize a bucket script result.
If I take the elasticsearch example :
POST /sales/_search
{
"size": 0,
"aggs" : {
"sales_per_month" : {
"date_histogram" : {
"field" : "date",
"interval" : "month"
},
"aggs": {
"t-shirts": {
"filter": {
"term": {
"type": "t-shirt"
}
},
"aggs": {
"sales": {
"sum": {
"field": "price"
}
}
}
},
"t-shirt-percentage": {
"bucket_script": {
"buckets_path": {
"tShirtSales": "t-shirts>sales"
},
"script": "if (params.tShirtSales < 10) { 1 } else if(params.tShirtSales >= 10 && params.tShirtSales < 50) { 2 } else { 3 }"
}
}
}
}
}
}
I'm trying to break out three categories according to the number of tshirt sales.
The categories if the number of tshirt sales are:
1. <10 => Category 1
2. 10-50 => Category 2
3. >50 => Category 3
I would like to know the number of tshirt sales for each category.
I thougt to use a terms aggregations on bucket script to display this category but the bucket script not accept sub aggregation.
Is-it possible ? Have you an idea please ?
Thank you in advance for your response.