# Collapse, Term Aggregation, Grouping

**URL:** <https://discuss.elastic.co/t/collapse-term-aggregation-grouping/307993>\
**Category:** Elasticsearch\
**Created:** [June 23, 2022, 11:01am UTC](https://discuss.elastic.co/t/collapse-term-aggregation-grouping/307993 "2022-06-23T11:01:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev\_test](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dev_test/32/79287_2.png) [@dev\_test](https://discuss.elastic.co/u/dev_test)\
**Post date:** [June 23, 2022, 11:01am UTC](https://discuss.elastic.co/t/collapse-term-aggregation-grouping/307993/1 "2022-06-23T11:01:33Z")

</div>

Hi there,  
I am using elasticsearch 7.17 and trying to group result on some field  
Here is the query which i am trying to run

```auto
GET content-data/_search
{
  "_source": false,
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "item_type_number": [
                    6,
                    8,
                    9,
                    10
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "term": {
                  "item_type_number": 1
                }
              },
              {
                "terms": {
                  "cluster_id": [
                    8
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "collapse": {
    "field": "section_type",
    "inner_hits": {
      "name": "sections",
      "size": 20,
      "sort": [
        {
          "order_id": {
            "order": "ASC"
          }
        }
      ]
    }
  }
}

```

the issue with this query is that it consumes all of the CPU processing and hence increasing the latency in results. when i run this query with without the field collapse no significant amount of CPU is consumed.  
previously i was using term aggregation to group results and retrieve fields but i was facing the same issue and now the collapse field is also becoming the bottleneck.

kindly help me with some mechanism to retrieve the result faster

---

<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:** [July 21, 2022, 11:02am UTC](https://discuss.elastic.co/t/collapse-term-aggregation-grouping/307993/2 "2022-07-21T11:02:25Z")

</div>

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