# Sort Alphabetically Ignoring Numbers & Special Characters

**URL:** <https://discuss.elastic.co/t/sort-alphabetically-ignoring-numbers-special-characters/161712>\
**Category:** Elasticsearch\
**Created:** [December 20, 2018, 3:02pm UTC](https://discuss.elastic.co/t/sort-alphabetically-ignoring-numbers-special-characters/161712 "2018-12-20T15:02:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shoutadnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shoutadnan/32/38612_2.png) [@shoutadnan](https://discuss.elastic.co/u/shoutadnan)\
**Post date:** [December 20, 2018, 3:02pm UTC](https://discuss.elastic.co/t/sort-alphabetically-ignoring-numbers-special-characters/161712/1 "2018-12-20T15:02:04Z")

</div>

How to sort a text field alphabetically, ignoring the special characters & numbers? By default, the special characters come first followed by numbers and alphabets.

What I need is alphabets should be sorted and appear first, followed by numbers and special characters. Is that even possible in **ES 6.3**?

I've tried with the custom analyzer to replace all non-alphabetical characters but it didn't work:

```
{
  "analysis": {
    "analyzer": {
      "alphabets_analyzer": {
        "tokenizer": "standard",
        "type": "keyword",
        "char_filter": [
          "alphabets_char_filter"
        ]
      }
    },
    "char_filter": {
      "alphabets_char_filter": {
        "type": "pattern_replace",
        "pattern": "[^a-zA-Z\\s\\.]",
        "replacement": ""
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [December 20, 2018, 3:23pm UTC](https://discuss.elastic.co/t/sort-alphabetically-ignoring-numbers-special-characters/161712/2 "2018-12-20T15:23:41Z")

</div>

Consider adding a field, consisting of the stripped values, at index time instead. Then just sort by that field as you normally would. It would be a much more simple setup, and better performing.

---

<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:** [January 17, 2019, 3:23pm UTC](https://discuss.elastic.co/t/sort-alphabetically-ignoring-numbers-special-characters/161712/3 "2019-01-17T15:23:52Z")

</div>

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