Dynamic mappings for particular fields

I'm using default mappings in ES that will set default type as "string" for message fields. But I need to set the type as "long" for particular dynamic fields.

In properties section of mapping file, I can insert manually those fields. But in my case, I have n-number of servers. thats so hard to update in mappings file.

Is there any option available ?. Please update.

Example message:

stats.info.dev1.srv 1000
stats.info.pro1.srv 2000
stats.info.uat1.srv 500
stats.info.uat15.srv 900
stats.info.pro2.srv 2400

I tried the below one in mapping field, but its not working.
"stats.info.*.srv ": {
"type": "long"
}

Someone please help.

Why not use a template instead?

Currently I'm using default template. but that's not suite for me since default type for all dynamic fields are set to "string".

Could you please share some template example for settings mapping type for particular dynamic fields ?

Try to add a template like this before you create your index.

curl -XPUT 'localhost:9200/_template/your_tp_name' -d '
{
        "order": 0,
        "template": "your_index_name",
        "settings": {
            "index.number_of_shards": "1"
        },
        "mappings": {
            "your_type_name": {
                "dynamic_templates": [
                    {
                        "long": {
                            "mapping": {
                                "type": "long"
                            },
                            "match": "stats*",
                            "match_mapping_type": "string"

                        }
                    }
                ]
            }
        },
        "aliases": {}
    }
}
'

After setting like above.
I post a doc like:

{
"test":123,
"test2":"123"
}

and got the mapping info like this:

"mappings":{
"test":{
"dynamic_templates":[{"string":{"mapping":{"type": "long" }, "match": "test*",…],
"properties":{
"test":{
"type": "long"
},
"test2":{
"type": "long"
}
}
}
}

Thanks for sharing the details with example.

I will check this one and will let you know the status soon.

@MrLee , I checked your suggested method. its working. But have one issue.

In my mappings file, I set all string should be "not_analyzed". But its not working. its comes as analyzed field.

If the value comes as "test_low" , its split into two string "test" and "low" . My intension is about to all string should be "not_analyzed" for particular document type. Is there any option to achieve ?

Mappings config

{
          "strings" : {
            "mapping" : {
              "index" : "not_analyzed",
              "type" : "string"
            },
            "match_mapping_type" : "string"
          } 

Mapping output :

              "Name" : {
                "type" : "string"
              },