Reputation: 368
I have query :
{
"size": 0,
"aggs": {
"data_bulanan" : {
"date_histogram" : {
"field" : "creation_date",
"interval" : "month",
"format": "MMMM"
},
"aggs": {
"SvcCharge" : {
"sum": {
"field": "service_tax"
}
},
"GvtTax" : {
"sum": {
"field": "government_tax"
}
},
"Discount" : {
"sum" : {
"field": "discount"
}
}
}
}
}
}
And i want to add the date range from date to date . for example from 2014-01-01 to 2015-01-01 .
How to add it?
thank you
Upvotes: 1
Views: 685
Reputation: 7472
If you'd like to limit the resultset to the specified dates above, you need to combine a query to your aggregation, you can do it like so
{
"size": 0,
"query": {
"bool": {
"filter": {
"range": {
"creation_date": {
"gte": "2014-01-01",
"lte": "2015-01-01"
}
}
}
}
},
"aggs": {
"data_bulanan": {
"date_histogram": {
"field": "creation_date",
"interval": "month",
"format": "MMMM"
},
"aggs": {
"SvcCharge": {
"sum": {
"field": "service_tax"
}
},
"GvtTax": {
"sum": {
"field": "government_tax"
}
},
"Discount": {
"sum": {
"field": "discount"
}
}
}
}
}
}
Upvotes: 2