# Facet sort does not work?

**URL:** <https://discuss.elastic.co/t/facet-sort-does-not-work/356650>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 3, 2024, 6:49am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650 "2024-04-03T06:49:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deshant\_Pandit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deshant_pandit/32/125663_2.png) [@Deshant\_Pandit](https://discuss.elastic.co/u/Deshant_Pandit)\
**Post date:** [April 3, 2024, 6:49am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/1 "2024-04-03T06:49:37Z")

</div>

```auto
export function buildFacetConfigFromConfig() {
  const config = getConfig();

  const facets = (config.facets || []).reduce((acc, n) => {
    acc = acc || {};
    acc[n] = {
      "sort": { "value": "asc" }, // this is for sort
      type: "value",
      size: 100
    };
    return acc;
  }, undefined);

  return facets;
}

```

I added sort but it sort first capital letters than small letter i.e, Azur, Bike, Gixer, Zebra, apple, banana. In this order but i want Azur, apple, banana, Bike, Gixer, Zebra.  
Please tell me the solution.

---

<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 3, 2024, 7:05am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/2 "2024-04-03T07:05:17Z")

</div>

You probably need to change the mapping and transform the text to lowercase.

Have a look at [normalizer | Elasticsearch Guide [8.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html)

---

<div class="post-metadata">

**Author:** ![Deshant\_Pandit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deshant_pandit/32/125663_2.png) [@Deshant\_Pandit](https://discuss.elastic.co/u/Deshant_Pandit)\
**Post date:** [April 3, 2024, 7:10am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/3 "2024-04-03T07:10:06Z")

</div>

in this one they're directly accessing core elasticsearch. but we're accessing through appsearch.

---

<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 3, 2024, 7:34am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/4 "2024-04-03T07:34:22Z")

</div>

Ok. I moved your question to #Elastic Search with the #enterprise-app-search tag.

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [April 3, 2024, 12:25pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/5 "2024-04-03T12:25:14Z")

</div>

Does your use case support case insensitivity? Then as @dadoonet suggested, adjusting your mappings and using a `lowercase` filter is the easiest way to resolve this.

---

<div class="post-metadata">

**Author:** ![Deshant\_Pandit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deshant_pandit/32/125663_2.png) [@Deshant\_Pandit](https://discuss.elastic.co/u/Deshant_Pandit)\
**Post date:** [April 3, 2024, 1:09pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/6 "2024-04-03T13:09:40Z")

</div>

No, It does not support case insensitivity.  
Result i get : Azur, Bike, Gixer, Zebra, apple, banana.  
Result i want: Azur, apple, banana, Bike, Gixer, Zebra.

I want it to be case iinsensitivity. Could you please elaborate How to do it?

Thanks

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [April 3, 2024, 2:38pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/7 "2024-04-03T14:38:52Z")

</div>

You want to normalize it when you index it, by defining a [custom analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html) in your mappings.

Here's an example of how it works:

```auto
PUT /lowercase_example/
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_filter": {
          "type": "custom",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "value": {
        "normalizer": "lowercase_filter",
        "type": "keyword"
      },
      "raw_value": {
        "type": "keyword"
      }
    }
  }
}

```

So you see here that I have an analyzer that will apply the lowercase filter. I have 2 keyword fields, 1 that uses this analyzer and one that doesn't.

Now let's add a few sample documents:

```auto
PUT lowercase_example/_doc/1
{
  "value": "Apple",
  "raw_value": "Apple"
}
PUT lowercase_example/_doc/2
{
  "value": "Banana",
  "raw_value": "Banana"
}
PUT lowercase_example/_doc/3
{
  "value": "avocado",
  "raw_value": "avocado"
}

```

If you do a terms aggregation on the raw value that doesn't use the lowercase filter, the results are out of the order that you want because they're case insensitive:

```auto
GET lowercase_example/_search
{
  "size": 0,
  "aggs": {
    "my_agg": {
      "terms": {
        "field": "raw_value",
        "order": { "_key": "asc" }
      }
    }
  }
}

```

However if you aggregate on the field you applied the filter it lowercases everything:

```auto
GET lowercase_example/_search
{
  "size": 0,
  "aggs": {
    "my_agg": {
      "terms": {
        "field": "value",
        "order": { "_key": "asc" }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Deshant\_Pandit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deshant_pandit/32/125663_2.png) [@Deshant\_Pandit](https://discuss.elastic.co/u/Deshant_Pandit)\
**Post date:** [April 4, 2024, 4:29am UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/8 "2024-04-04T04:29:51Z")

</div>

Thanks for detailed explanation. It is not elasticsearch, but elastic appsearch. There is no option to use case insensitive facet results in appsearch. Could you please help me to resolve this one in appsearch?

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [April 4, 2024, 12:31pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/9 "2024-04-04T12:31:13Z")

</div>

You can absolutely use this strategy in App Search using an [Elasticsearch index engine](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines.html).

As you can see in the screenshot, I plugged in the example I gave you and created an engine, and the lowercase normalizer does what you're asking for.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/e/3eb9e0ceb20a5a168f47b575dcc1aeba2fc01746.png)

---

<div class="post-metadata">

**Author:** ![Deshant\_Pandit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deshant_pandit/32/125663_2.png) [@Deshant\_Pandit](https://discuss.elastic.co/u/Deshant_Pandit)\
**Post date:** [April 4, 2024, 12:44pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/10 "2024-04-04T12:44:32Z")

</div>

Thanks  
I want

- Apple
- avacado
- Banana  
this sequence (all the A's or a's irrespective of capital or small then B's or b's and so on )  
Please suggest?

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [April 4, 2024, 1:31pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/11 "2024-04-04T13:31:02Z")

</div>

You can experiment with other mappings to see if you can get what you want, or experiment with other ways to do this on the client side.

---

<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:** [May 2, 2024, 1:31pm UTC](https://discuss.elastic.co/t/facet-sort-does-not-work/356650/12 "2024-05-02T13:31:24Z")

</div>

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