How to increase performance of query using filter?

{
"size": 0,
"filter": [
{
"term": {
"type": "type_data"
}
},
{
"exists": {
"field": "ID"
}
}
],
"aggs": {
"group_by_state": {
"terms": {
"field": "name",
"size": 0,
"order": {
"_term": "asc"
}
},
"aggs": {
"Average": {
"avg": {
"field": "AVG_FIELD1"
}
},
"99th Percentile": {
"percentiles": {
"field": "AVG_FIELD2",
"percents": [
99
]
}
}
}
}
}
}

I am using above query but it takes too much time to execute. There are about 1900000 events. How can i optimize above query? should I use filter ?

Hi @rupal,

you can use the profile API (available in ES 2.2+) to dig deeper. I guess your problem are the aggregations.

Daniel