# Dynamic mappings for particular fields

**URL:** <https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048>\
**Category:** Elasticsearch\
**Created:** [May 3, 2016, 11:50am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048 "2016-05-03T11:50:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [May 3, 2016, 11:50am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/1 "2016-05-03T11:50:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [May 4, 2016, 8:44am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/2 "2016-05-04T08:44:05Z")

</div>

I tried the below one in mapping field, but its not working.  
"[stats.info](http://stats.info).\*.srv ": {  
"type": "long"  
}

Someone please help.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 4, 2016, 10:42am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/3 "2016-05-04T10:42:09Z")

</div>

Why not use a template instead?

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [May 4, 2016, 11:04am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/4 "2016-05-04T11:04:29Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![MrLee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrlee/32/9429_2.png) [@MrLee](https://discuss.elastic.co/u/MrLee)\
**Post date:** [May 4, 2016, 11:47am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/5 "2016-05-04T11:47:32Z")

</div>

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

```auto
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": {}
    }
}
'

```

---

<div class="post-metadata">

**Author:** ![MrLee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrlee/32/9429_2.png) [@MrLee](https://discuss.elastic.co/u/MrLee)\
**Post date:** [May 4, 2016, 12:15pm UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/6 "2016-05-04T12:15:38Z")

</div>

After setting like above.  
I post a doc like:

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

```

and got the mapping info like this:

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

```

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [May 4, 2016, 12:29pm UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/7 "2016-05-04T12:29:40Z")

</div>

Thanks for sharing the details with example.

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

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [June 17, 2016, 8:21am UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/8 "2016-06-17T08:21:33Z")

</div>

@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"
> },
> 
> ```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:42pm UTC](https://discuss.elastic.co/t/dynamic-mappings-for-particular-fields/49048/9 "2017-07-05T22:42:49Z")

</div>


