Search code examples
elasticsearchmongoosastic

How to approach non-latin characters in ElasticSearch autocompletion with Mongoosastic?


Autocompletion is working fine using es.search({size: 0, suggest: ...} using completion mapping on a field that can have non-latin diacritics (accented characters like â, ê, etc.).

I am creating mappings using mongoosastic. I need to be able to use something like asciifolding for suggestions or add additional field to the response.

I have those fields:

  • name which is the one with diacritics.
  • nameSearch which is the name latinized (no diacritics/accented characters).

What I need is to either continue completion suggestions over name but treat a the same as â (and the other way).

In the response I need name. Not nameSearch.


Solution

  • I stumbled on this problem again, this time without mongoosastic. The answer is to have settings field in the index query (in mongoosastic you can add it when using custom mappings).

    settings: {
      analysis: {
        analyzer: {
          folding: {
            tokenizer: 'standard',
            filter: ['lowercase', 'custom_asciifolding'],
          },
        },
        filter: {
          custom_asciifolding: {
            type: 'asciifolding',
            preserve_original: true,
          },
        },
      },
    }