# Character filter analyzer not working

**URL:** <https://discuss.elastic.co/t/character-filter-analyzer-not-working/288531>\
**Category:** Elasticsearch\
**Created:** [November 6, 2021, 12:09am UTC](https://discuss.elastic.co/t/character-filter-analyzer-not-working/288531 "2021-11-06T00:09:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Juliano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_juliano/32/48845_2.png) [@Kevin\_Juliano](https://discuss.elastic.co/u/Kevin_Juliano)\
**Post date:** [November 6, 2021, 12:09am UTC](https://discuss.elastic.co/t/character-filter-analyzer-not-working/288531/1 "2021-11-06T00:09:24Z")

</div>

Hi!

I have a special character analyzer, but for some reason, I am not getting the result I want. Here are my configurations:

ANALYZER:

```auto
{
          index: "my_idx",
          body: {
            settings: {
              analysis: {
                analyzer: {
                  my_analyzer: {
                    tokenizer: "whitespace",
                    filter: ["lowercase", "kstem"],
                  },
                  alphanumericStringAnalyzer: {
                      filter: "lowercase",
                      char_filter: [
                          "specialCharactersFilter"
                      ],
                      type: "custom",
                      tokenizer: "standard"
                  }
                },
                char_filter: {
                  specialCharactersFilter: {
                      pattern: "[^A-Za-z0-9]",
                      type: "pattern_replace",
                      replacement: ""
                  }
                }
              },
            },
          },
        }

```

FIELD MAPPING:

```auto
{
    properties: {
      id: { type: "integer", index: false },
      serial_number: { type: "integer", index: true },
      title: {
        type: "text",
        index: true,
        analyzer: "my_analyzer",
      },
      class: {
        properties: {
          text: {
            type: "text",
            fields: {
            alphanumeric: {
              type: "text",
                  analyzer: "alphanumericStringAnalyzer"
                  search_analyzer: "my_analyzer"
              },
              raw: {
                  type: "keyword"
              }
            },
            index: true
          }
        }
      }
    }
  }

```

SEARCH QUERY: with singular "hat" in class.text

```auto
{
    "query": {
    "bool": {
      "must": [
        { "match": { "title": "THIS LOVE" } },
        {
          "bool": {
            "should": [{ "match": { "class.text": "hat" } }]
          }
        }
      ]
    }
  }
}

```

TOP RESULT :

```auto
{
                "_index": "my_idx",
                "_type": "idx",
                "_id": "PkNFl3kBpXYO8ovFwRgy",
                "_score": 16.819193,
                "_source": {
                    "id": 55286400,
                    "class": [
                        {
                            "text": "Clothing, namely, hat, t-shirts, and jackets"
                        }
                    ],
                    "title": "YOUR LOVE",
                    "serial_number": 00000000,
                    "@version": "1",
                    "@timestamp": "2021-05-23T03:30:01.052Z"
                }
            }

```

NEXT SEARCH QUERY: Change "hat" to "Hats"

```auto
{
    "query": {
    "bool": {
      "must": [
        { "match": { "title": "THIS LOVE" } },
        {
          "bool": {
            "should": [{ "match": { "class.text": "hats" } }]
          }
        }
      ]
    }
  }
}

```

TOP RESULT: this is also what I am expecting if I also search for a singular "hat"

```auto
{
                "_index": "my_idx",
                "_type": "idx",
                "_id": "PkNFl3kBpXYO8ovFwRgy",
                "_score": 20.108686,
                "_source": {
                    "id": 54039674,
                    "class": [
                        {
                            "text": "Hats; T-shirts"
                        }
                    ],
                    "title": "THIS LOVE",
                    "serial_number": 00000001,
                    "@version": "1",
                    "@timestamp": "2021-05-23T03:30:01.052Z"
                }
            }

```

The difference between them is the result, the one that I wanted has "Hats;" in it, I want to get that result too when searching for the singular "hat".

Did I make a mistake anywhere?  
Is this the right way to configure this?

Please help.

---

<div class="post-metadata">

**Author:** ![Kevin\_Juliano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_juliano/32/48845_2.png) [@Kevin\_Juliano](https://discuss.elastic.co/u/Kevin_Juliano)\
**Post date:** [November 8, 2021, 1:28pm UTC](https://discuss.elastic.co/t/character-filter-analyzer-not-working/288531/2 "2021-11-08T13:28:52Z")

</div>

anyone?

---

<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:** [December 6, 2021, 1:29pm UTC](https://discuss.elastic.co/t/character-filter-analyzer-not-working/288531/3 "2021-12-06T13:29:52Z")

</div>

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