Analyzer rule based on properties with wildcard

Hi,

I need to store documents with content in several different languages in a same document.
In order to store these documents, I was thinking of suffixing these properties with the corresponding language code.

Example:
json = { "text_en": "the text in English", "text_fr": "the text in French", "text_ru": "the text in Russian", "another_text_it": "this one in Italian"}

These document will also be nested objects and the structure will not be fixed.

Therefore I was looking for a solution to create a mapping that would consider "suffixes" to apply language-specific analyzers, such as:

"mappings": {
...
"properties": {
"_en": {
"type": "string",
"language": "english"
},
"
_fr": {
"type": "string",
"language": "french"
}
...and so forth.

Could somebody tell me if this is possible?

Many thanks

Take a look at dynamic templates. Dynamic templates allow you to define mappings based on wildcards matching a field name.

Something like this should do what you are trying to achieve:

  "mappings": {
    "my_type": {
      "dynamic_templates": [
        {
          "english_fields": {
            "match": "*_en",
            "mapping": {
              "analyzer": "english"
            }
          }
        },
        {
          "french_fields": {
            "match": "*_fr",
            "mapping": {
              "analyzer": "french"
            }
          }
        }
      ]
    }
  }