# Performance tuning for aggregators

**URL:** <https://discuss.elastic.co/t/performance-tuning-for-aggregators/240050>\
**Category:** Elasticsearch\
**Created:** [July 6, 2020, 6:21pm UTC](https://discuss.elastic.co/t/performance-tuning-for-aggregators/240050 "2020-07-06T18:21:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratikgcet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratikgcet/32/71680_2.png) [@pratikgcet](https://discuss.elastic.co/u/pratikgcet)\
**Post date:** [July 6, 2020, 6:21pm UTC](https://discuss.elastic.co/t/performance-tuning-for-aggregators/240050/1 "2020-07-06T18:21:37Z")

</div>

Hello,  
I have a below query which is doing mulitple aggregations and then returning the data. I am doing a filter on date greater than 7am this morning. The elasticsearch has got millions of rows and I expected the below query to be much faster than it really is. ANy performance or dos and donts in the below query will be really appreciated. I am searching on securityID field. This is using nodejs.  
Number of replica -1  
Single cluster  
4gb heap size  
The below query for one securityID takes 6 seconds to return. The document is a json

`  
var d = new Date();

d.setHours(7,0,0,0);  
return await client.search({

```
index:'axes_db',
size:0,
body: { 
  aggs: {
    "filterAggregator": {
      filter: 
      {
        bool:{     
                  must_not:[
                    { match:{"IOIQty":'0'}} ] ,              

                  must:[
                    {range:{InsertionTime:{'gte':d}}},    
                    {
                      match:{
                      SecurityID:{
                        query:`${a b c d}`,
                        operator:'OR',
                      }
                    }
                    },                         
                  ]
            }
      } ,
      aggs: {
        "first_by_broker": {
          terms: {
          field: "Broker.keyword",
         // size:90000,
          // shard_size:100000
          },
          aggs: {
          "then_by_side": {
            terms: {
            field: "Side.keyword",
            // sizesize:100000
            },
            aggs: {
            "then_by_symbol": {
              terms: {
              field: "SecurityID.keyword",
              // size:90000,
              // shard_size:100000
              },
              aggs: {
              "get_top_record": {

                top_hits: {

                sort: [

                          {

                              "InsertionTime": {

                                  order: "desc"

                              }

                          }

                      ],

                  size : 1

                }

              }

            }

                }

              }          

            }

          }

        }

      }

    }

  }

}

```

})`

Here are the stats  
{"indices":{"axes\_db":{"primaries":{"refresh":{"total":181,"total\_time\_in\_millis":53666,"external\_total":176,"external\_total\_time\_in\_millis":53826,"listeners":0},"segments":{"count":43,"memory\_in\_bytes":1232452,"terms\_memory\_in\_bytes":363952,"stored\_fields\_memory\_in\_bytes":818408,"term\_vectors\_memory\_in\_bytes":0,"norms\_memory\_in\_bytes":46784,"points\_memory\_in\_bytes":0,"doc\_values\_memory\_in\_bytes":3308,"index\_writer\_memory\_in\_bytes":11276192,"version\_map\_memory\_in\_bytes":4893868,"fixed\_bit\_set\_memory\_in\_bytes":0,"max\_unsafe\_auto\_id\_timestamp":-1,"file\_sizes":{}}},"total":{"refresh":{"total":181,"total\_time\_in\_millis":53666,"external\_total":176,"external\_total\_time\_in\_millis":53826,"listeners":0},"segments":{"count":43,"memory\_in\_bytes":1232452,"terms\_memory\_in\_bytes":363952,"stored\_fields\_memory\_in\_bytes":818408,"term\_vectors\_memory\_in\_bytes":0,"norms\_memory\_in\_bytes":46784,"points\_memory\_in\_bytes":0,"doc\_values\_memory\_in\_bytes":3308,"index\_writer\_memory\_in\_bytes":11276192,"version\_map\_memory\_in\_bytes":4893868,"fixed\_bit\_set\_memory\_in\_bytes":0,"max\_unsafe\_auto\_id\_timestamp":-1,"file\_sizes":{}}}}}}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 3, 2020, 6:31pm UTC](https://discuss.elastic.co/t/performance-tuning-for-aggregators/240050/2 "2020-08-03T18:31:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
