# Custom mapping / dynamic\_templates json\_data

**URL:** <https://discuss.elastic.co/t/custom-mapping-dynamic-templates-json-data/82136>\
**Category:** Elasticsearch\
**Created:** [April 12, 2017, 10:00am UTC](https://discuss.elastic.co/t/custom-mapping-dynamic-templates-json-data/82136 "2017-04-12T10:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cajb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cajb/32/17285_2.png) [@cajb](https://discuss.elastic.co/u/cajb)\
**Post date:** [April 12, 2017, 10:00am UTC](https://discuss.elastic.co/t/custom-mapping-dynamic-templates-json-data/82136/1 "2017-04-12T10:00:33Z")

</div>

Hello,

I'm trying to index a document which has a property called "json\_data" (type "object").  
{  
"json\_data": {"id": 1, "level": 1, "data": {another json...}}  
}

I'm trying to create a template with dynamic\_templates so that every value of "json\_data" on every level (id, level, data.key1, data.key2, data.key1.subkey1... etc) to be indexed as string.

The error I get is:

"status"=\>400,  
"error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"failed to parse [json\_data.data]", "caused\_by"=\>{"type"=\>"illegal\_state\_exception", "reason"=\>"Can't get text on a START\_OBJECT at 1:55"}}

How can I apply dynamic\_templates/mapping for all the properties/subproperties of this object? I don't know the names of the properties in advance so I need to use dynamic\_templats.

{  
"template" : "logstash-_",  
"mappings" : {  
"default" : {  
"dynamic\_templates" : [  
{  
"json\_data\_as\_strings" : {  
"path\_match" : "json\_data._",  
"mapping" : {  
"type" : "string",  
"index": "not\_analyzed",  
}  
}  
}  
]  
}  
}  
}

Thank you,

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [April 13, 2017, 8:20am UTC](https://discuss.elastic.co/t/custom-mapping-dynamic-templates-json-data/82136/2 "2017-04-13T08:20:15Z")

</div>

Hi,

Did you see 'path\_match' ?  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.3/dynamic-templates.html#path-match-unmatch](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/dynamic-templates.html#path-match-unmatch)

---

<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:** [May 11, 2017, 8:21am UTC](https://discuss.elastic.co/t/custom-mapping-dynamic-templates-json-data/82136/3 "2017-05-11T08:21:44Z")

</div>

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