# Label for facet values

**URL:** <https://discuss.elastic.co/t/label-for-facet-values/251016>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [October 5, 2020, 3:19pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016 "2020-10-05T15:19:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swapnil\_Ghorpade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swapnil_ghorpade/32/56943_2.png) [@Swapnil\_Ghorpade](https://discuss.elastic.co/u/Swapnil_Ghorpade)\
**Post date:** [October 5, 2020, 3:19pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016/1 "2020-10-05T15:19:48Z")

</div>

How to show label instead of values in facets.

For example: Consider following facets  
`country_data: [{ title: "Wrangell–St1", country : "US" }, { title: "Wrangell–St2", country : "IN" }]`

Where i have to show countries in facet based on custom display names at client side rendering.

map displayNames / label's from : countyNames: `{"US" : "United States", "IN" : "India" }` which is getting from backend.

```
Country
     - United States (1)
     - India (2)

```

Is there anything like label or title that I can use to show this?

Thanks in advance!  
Regards

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [October 20, 2020, 3:48pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016/2 "2020-10-20T15:48:15Z")

</div>

Hi @Swapnil_Ghorpade, this is something you'll need to code yourself on the front end. There's no way to provide labels for facet values automatically.

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [October 20, 2020, 3:49pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016/3 "2020-10-20T15:49:12Z")

</div>

Your other option would be to do it at Index time. You could index two fields ... `country` and `country_display`.

---

<div class="post-metadata">

**Author:** ![Swapnil\_Ghorpade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swapnil_ghorpade/32/56943_2.png) [@Swapnil\_Ghorpade](https://discuss.elastic.co/u/Swapnil_Ghorpade)\
**Post date:** [October 21, 2020, 3:25pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016/4 "2020-10-21T15:25:42Z")

</div>

@JasonStoltz Thanks for the response.

Yes, I tried other thing which gives me expected output.  
I can able to show any custom string as label to facet value.

please correct me if I am doing anything wrong

here is the Code:

```
const apiConnector = new AppSearchAPIConnector({
 searchKey: searchKey,
 engineName: engineName,
 hostIdentifier: hostIdentifier,
 beforeSearchCall: async (existingSearchOptions, next) => {
   const existingFilters = existingSearchOptions.filters || { none: [] };

   const existingFiltersAll = existingFilters.all ? existingFilters.all : [];

      existingFiltersAll.map((allFilter) => {
         const existingFiltersAny = allFilter.any;
         return existingFiltersAny.map((filter) => {
         const obj = filter;

        // Replace type value label with actual index id to search
        if (filter.type) {
           obj.type = getIdByLabel(filter.type);
        }

        return obj;
      });
   });

   const results = await next({
     ...existingSearchOptions,
     filters,
  });

  // Replace Types id with display name in facets
  results.facets.type[0].data = results.facets.type[0].data.map((result) => {
    const obj = result;
    obj.value = getLabelById(result.value);
    return obj;
  });

    return results;
   },
});
```

---

<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 18, 2020, 3:25pm UTC](https://discuss.elastic.co/t/label-for-facet-values/251016/5 "2020-11-18T15:25:52Z")

</div>

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