# How to create an index with combination of fields and dynamic template?

**URL:** <https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006>\
**Category:** Elasticsearch\
**Created:** [October 26, 2016, 1:12pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006 "2016-10-26T13:12:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nethis](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nethis](https://discuss.elastic.co/u/nethis)\
**Post date:** [October 26, 2016, 1:12pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006/1 "2016-10-26T13:12:55Z")

</div>

I have to create an index, with 20 fields as known type and fixed fields, so I can specify the properties of those fields and , there is an object called dimensions, with unknown field names. So, I have to create a dynamic template, just for inner fields in the dimensions object with type string and as not\_analyzed field. Please help me here

here is the one, I tried to create , but not successful.

PUT my\_index  
{  
"mappings": {  
"my\_type": {  
"properties": {  
"status\_code": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"session\_id": {  
"type": "long",  
"Dimensions":  
{  
"dynamic\_templates": [  
{  
"testname": {  
"match": "\*",  
"mapping": {  
"type": "string",  
"index": "not\_analyzed",  
"doc\_values": true  
}  
}  
}]  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![nethis](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nethis](https://discuss.elastic.co/u/nethis)\
**Post date:** [October 26, 2016, 1:29pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006/2 "2016-10-26T13:29:56Z")

</div>

I can create like this, but properties are not being applied for the new fields added under customdimensions object.

PUT testindex  
{  
"mappings": {  
"test\_type":{  
"dynamic\_templates": [  
{  
"name\_template": {  
"match": "customdimension.\*",  
"mapping": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
],  
"properties": {  
"cloudRoleName": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"componentName": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![nethis](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nethis](https://discuss.elastic.co/u/nethis)\
**Post date:** [October 28, 2016, 4:25am UTC](https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006/3 "2016-10-28T04:25:05Z")

</div>

This can be achieved by dynamic template for nested fields. See the example below

"error": {  
"settings": {  
"index": {  
"number\_of\_shards": 20,  
"number\_of\_replicas": 2  
}  
},  
"mappings": {  
"dailyaggregate": {  
"dynamic\_templates": [  
{  
"string\_template": {  
"match\_mapping\_type": "string",  
"mapping": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
{  
"customDim\_template": {  
"match": "custom\*",  
"mapping": {  
"type": "nested"  
}  
}  
},  
{  
"nested\_template": {  
"path\_match": "custom\*.\*",  
"mapping": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
],  
"properties": {  
"@timestamp": {  
"type": "date",  
"format": "strict\_date\_optional\_time||epoch\_millis"  
}  
}  
}  
}

---

<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:08pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-with-combination-of-fields-and-dynamic-template/64006/4 "2017-07-05T22:08:52Z")

</div>


