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).

Taranjeet
  • 583
  • 2
  • 9
  • 20

1 Answers1

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!!

Richa
  • 7,419
  • 6
  • 25
  • 34
  • 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` – Taranjeet May 11 '17 at 18:07
  • That was not what the question mentioned. Question Was about `Regex expression` and the answers addresses that problem. Create another question for that – Richa May 12 '17 at 04:23
  • Sure. Thanks for the help – Taranjeet May 12 '17 at 05:47