# Collapse inner hits

**URL:** <https://discuss.elastic.co/t/collapse-inner-hits/151337>\
**Category:** Elasticsearch\
**Created:** [October 7, 2018, 6:56am UTC](https://discuss.elastic.co/t/collapse-inner-hits/151337 "2018-10-07T06:56:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zouxiang](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@zouxiang](https://discuss.elastic.co/u/zouxiang)\
**Post date:** [October 7, 2018, 6:56am UTC](https://discuss.elastic.co/t/collapse-inner-hits/151337/1 "2018-10-07T06:56:10Z")

</div>

I use _ **collapse** _ to get goods with the lowest price:

```auto
GET xxx/sku/_search
{
  "from": 0,
  "size": 10,
  "sort": [
    {
      "firstUpTime": {
        "order": "desc"
      }
    }
  ],
  "collapse": {
    "field": "goodsWebSpu",
    "inner_hits": {
      "name": "skus",
      "size": 1,
      "sort": [
        {
          "displayPrice": {
            "order": "asc"
          }
        }
      ]
    }
  }
}

```

It works correctly but it's too expensive for the cluster to execute this query.

> **[Field Collapsing | Elasticsearch Reference \[5.5\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-collapse.html)**

The office document says,

> The expansion of the group is done by sending an additional query for each `inner_hit` request for each collapsed hit returned in the response. This can significantly slow things down if you have too many groups and/or `inner_hit` requests.

My test result:

 ![collapse2](https://us1.discourse-cdn.com/elastic/original/3X/0/b/0b27e3688fc05b71eb239424d25424c5334042ec.png)

Is there any more efficient way to do this?

---

<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:** [November 4, 2018, 6:56am UTC](https://discuss.elastic.co/t/collapse-inner-hits/151337/2 "2018-11-04T06:56:11Z")

</div>

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