0

ElasticSearch supports mapping char filter, where in one can specify a key and its corresponding value. I want to use regular expression in key.

The regular expression I am trying is basically to catch all uppercase symbols ending with I and convert them to strings ending with l. So this looks something like

ABCI => ABCl

String before I is not fixed, hence I am writing regular expression.

I have figured out the left hand part of the expression as [A-Z]+I but I am not able to decide what should be written on the right hand side so that I can catch string ABC as well.

My question is can we use regular expression in mapping char filter. If yes then how can I write the concerned regular expression(especially the right hand side part).

1 Answer 1

1

Use Pattern Replace Char Filter:

{
"settings": {
"analysis": {
  "analyzer": {
    "my_analyzer": {
      "tokenizer": "standard",
      "char_filter": [
        "my_char_filter"
      ]
    }
  },
  "char_filter": {
    "my_char_filter": {
     "type": "pattern_replace",
      "pattern": "([A-Z]+)(I)$",   ==> Patterm containg uppaer case characters ending with I
      "replacement": "$11"         =>  Replacing Group 1 with '1'
      }
     }
    }
   }
 }

hope this helps!!

Sign up to request clarification or add additional context in comments.

3 Comments

This solution is fine for one key, but I have a case where in I which keys will be updated when ES is running. What about that ? I was looking for something as flexible as synonyms file
That was not what the question mentioned. Question Was about Regex expression and the answers addresses that problem. Create another question for that
Sure. Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.