Character filter analyzer not working

Hi!

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

ANALYZER:

{
          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:

{
    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

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

TOP RESULT :

{
                "_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"

{
    "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"

{
                "_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.

anyone?

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