Field Mapping using Wildcards - Newbie Question

Hi Experts,

Is it possible to have wildcard type fields mapping ? What i mean is, like in SOLR we can define dynamicFields mapping saying map *_txt_en to text_en (convention i am trying to use is "fieldName_type_language" and then we define text_en as text field with english analyzer and so on. Or may be do direct mapping, I tried

{
  "mappings": {
    "type1": {
      "properties": {
        "*_i_en": {
          "type": "integer"
        }
      }
    }
  }
}

and tried indexing below field
{
"age_i_en":25
}

I checked metadata and it was indexed as long, but not as integer. What i am trying to achieve is define wildcard/regular expression type mappings, so that i can define customize pipelines and so on. And during runtime fields names will get resolved automatically and this way i don't have to define/tie fields names. Also during query time is it possible to specify "age_i_*" as query field rather than complete name, so that if i have fields with multiple languages then i don't have to iterate over each of them ?

Any help is appreciated.

Regards,
Lukes

@lukes Yes, wildcard type fields mapping is possible through dynamic mapping templates . Look at following mapping:

PUT my_index
{
  "mappings": {
    "my_type": {
      "dynamic_templates": [
        {
          "_i_en_as_integers": {
            "match_mapping_type": "*",
            "match":   "*_i_en",
            "mapping": {
              "type": "integer"
            }
          }
        }
      ]
    }
  }
}

You can read more about dynamic mapping templates here.

Yes, this is possible. You can simply search records like this:

GET my_index/_search
{
    "query": {
        "query_string" : {
            "default_field" : "age_i_*",
            "query" : "25 30"
        }
    }
}

OR

GET my_index/_search
{
    "query": {
        "query_string" : {
            "query" : "age_i_\\*:25 OR age_i_\\*:30"
        }
    }
}

Hope this helps :slight_smile:

Thanks @avr. I'll give it a shot.

Regards,
Lukes

That's exactly what i was looking for. Thanks a lot.

Regards,
Lukes

@lukes Glad you found it. You can mark the question answered if you feel no further discussion is needed! :slight_smile:

sure....

Regards,
Lukes

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