# Faceting after Collapse

**URL:** <https://discuss.elastic.co/t/faceting-after-collapse/356453>\
**Category:** Elasticsearch\
**Created:** [March 29, 2024, 9:56am UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453 "2024-03-29T09:56:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fvsadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fvsadem/32/131873_2.png) [@fvsadem](https://discuss.elastic.co/u/fvsadem)\
**Post date:** [March 29, 2024, 9:56am UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453/1 "2024-03-29T09:56:15Z")

</div>

Hi,

I struggle to migrated from Algolia to Elasticsearch.  
My problem is facet after distinct option equivalent in Elasticsaerch. I successfuly collapse my index to distinct by an attribute but there is a problem with the facets. The facets counts have the wrong number of items, the no collapse's results.

I want my facets counts have the number after collapse, not before collapse.

There is my params that i use with the attribute for distinct "sku" :

```auto
{
  "query": {
    "match_all": {}
  },
  "collapse": {
    "field": "sku"
  },
  "aggs": {
    "skus_after_collapsing": {
      "terms": {
        "field": "sku.keyword"
      }
    },
    ...
    }
  }
}

```

My mapping for the filed "sku" :

```auto
"sku": {
    "type": "keyword"
},

```

Do someone have an idea ?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 29, 2024, 11:36am UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453/2 "2024-03-29T11:36:51Z")

</div>

Bonjour 😉

I'm not sure I fully understood what you are getting and what you would like to get.

Could you illustrate that with a simple basic example?

Like could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the [Elastic Stack and Solutions Help · Forums and Slack | Elastic](https://elastic.co/community/help) page. It contains also lot of useful information on how to ask for help.

---

<div class="post-metadata">

**Author:** ![fvsadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fvsadem/32/131873_2.png) [@fvsadem](https://discuss.elastic.co/u/fvsadem)\
**Post date:** [April 2, 2024, 2:39pm UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453/3 "2024-04-02T14:39:22Z")

</div>

Hi Dadoonet,

Sorry how could i reproduce my problem ? it's a localy elasticsearch server.

Do you have a codesandbox or something that help me to recreate the problem ?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 2, 2024, 4:26pm UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453/4 "2024-04-02T16:26:13Z")

</div>

The last link I shared explains that I think.

---

<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:** [April 30, 2024, 4:26pm UTC](https://discuss.elastic.co/t/faceting-after-collapse/356453/5 "2024-04-30T16:26:38Z")

</div>

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