# Is it possible to create mapping for fields following a pattern or wildcard?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513>\
**Category:** Elasticsearch\
**Created:** [November 3, 2010, 10:57pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513 "2010-11-03T22:57:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diptamay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diptamay/32/2805_2.png) [@Diptamay](https://discuss.elastic.co/u/Diptamay)\
**Post date:** [November 3, 2010, 10:57pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513/1 "2010-11-03T22:57:07Z")

</div>

Hi Shay

I have documents of this type as listed under [https://gist.github.com/661688](https://gist.github.com/661688)

I was wondering if I could create mappings for fields that follow a  
certain pattern, as against ES determining dynamically how to index,  
store etc those fields. As an example, I want all the nested field  
values under "tags" section/object in the documents to all be treated  
as Strings. So I am looking to define a mapping like the following.  
Note the "\*" below under "tags".

{  
"video" : {  
"dynamic" : true,  
"enabled" : true,  
"date\_formats" : [  
"dateOptionalTime",  
"yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"  
],  
"\_source" : {  
"enabled" : true,  
"compress" : true,  
"name" : "\_source"  
},  
"properties" : {  
"itemType" : {  
"store" : "yes",  
"type" : "string"  
},  
"userDate" : {  
"store" : "yes",  
"format" : "dateOptionalTime",  
"type" : "date"  
},  
"tags" : {  
"properties" : {  
"\*" : {  
"properties" : {  
"value" : {  
"type" : "string"  
},  
"displayName" : {  
"type" : "string"  
}  
},  
"type" : "object"  
}  
}  
}  
},  
"\_all" : {  
"enabled" : true,  
"store" : "no",  
"term\_vector" : "no"  
},  
"type" : "object"  
}  
}

So whenever, a document would have, something like the following tags  
object, all the object values listed under combined\_media\_state/  
player\_id/team\_id, would be treated as strings as against dynamically  
decided by ES like integer for player\_id.value

"tags" : {  
"combined\_media\_state" : [ {  
"value" : "MEDIA\_ON",  
"displayName" : "MEDIA\_ON"  
} ],  
"weight" : [ {  
"value" : "1",  
"displayName" : "1"  
} ],  
"subject" : [ {  
"value" : "MLBCOM\_FEATURE",  
"displayName" : "MLBCOM\_FEATURE"  
} ],  
"mlbtax" : [ {  
"value" : "mm\_hightlight\_reel",  
"displayName" : "highlight reel"  
}, {  
"value" : "home\_run",  
"displayName" : "home run"  
} ],  
"player\_id" : [ {  
"value" : "121347",  
"displayName" : "Alex Rodriguez"  
} ],  
"team\_id" : [ {  
"value" : "147",  
"displayName" : "New York Yankees"  
} ]  
}

I guess, this is probably not there right now. Would it be possible to  
add this as a feature request or is it too much of a hassle?

Thanks  
Diptamay

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 3, 2010, 11:20pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513/2 "2010-11-03T23:20:47Z")

</div>

There is the dynamic templates feature:  
[http://www.elasticsearch.com/docs/elasticsearch/mapping/root\_object\_type/#dynamic\_templates](http://www.elasticsearch.com/docs/elasticsearch/mapping/root_object_type/#dynamic_templates),  
but it can only be defined on the root object mapping, so no notion of  
applying (matching) the template only for specific objects (like tags in  
your case). But, it can be easily added by adding, on top of `match`, also  
`path_match`, which will match on the current object "path", in your case  
its tags. You can open a feature for it.

-shay.banon

On Thu, Nov 4, 2010 at 12:57 AM, diptamay [diptamay@gmail.com](mailto:diptamay@gmail.com) wrote:

> Hi Shay
> 
> I have documents of this type as listed under  
> [661688’s gists · GitHub](https://gist.github.com/661688)
> 
> I was wondering if I could create mappings for fields that follow a  
> certain pattern, as against ES determining dynamically how to index,  
> store etc those fields. As an example, I want all the nested field  
> values under "tags" section/object in the documents to all be treated  
> as Strings. So I am looking to define a mapping like the following.  
> Note the "\*" below under "tags".
> 
> {  
> "video" : {  
> "dynamic" : true,  
> "enabled" : true,  
> "date\_formats" : [  
> "dateOptionalTime",  
> "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"  
> ],  
> "\_source" : {  
> "enabled" : true,  
> "compress" : true,  
> "name" : "\_source"  
> },  
> "properties" : {  
> "itemType" : {  
> "store" : "yes",  
> "type" : "string"  
> },  
> "userDate" : {  
> "store" : "yes",  
> "format" : "dateOptionalTime",  
> "type" : "date"  
> },  
> "tags" : {  
> "properties" : {  
> "\*" : {  
> "properties" : {  
> "value" : {  
> "type" : "string"  
> },  
> "displayName" : {  
> "type" : "string"  
> }  
> },  
> "type" : "object"  
> }  
> }  
> }  
> },  
> "\_all" : {  
> "enabled" : true,  
> "store" : "no",  
> "term\_vector" : "no"  
> },  
> "type" : "object"  
> }  
> }
> 
> So whenever, a document would have, something like the following tags  
> object, all the object values listed under combined\_media\_state/  
> player\_id/team\_id, would be treated as strings as against dynamically  
> decided by ES like integer for player\_id.value
> 
> "tags" : {  
> "combined\_media\_state" : [ {  
> "value" : "MEDIA\_ON",  
> "displayName" : "MEDIA\_ON"  
> } ],  
> "weight" : [ {  
> "value" : "1",  
> "displayName" : "1"  
> } ],  
> "subject" : [ {  
> "value" : "MLBCOM\_FEATURE",  
> "displayName" : "MLBCOM\_FEATURE"  
> } ],  
> "mlbtax" : [ {  
> "value" : "mm\_hightlight\_reel",  
> "displayName" : "highlight reel"  
> }, {  
> "value" : "home\_run",  
> "displayName" : "home run"  
> } ],  
> "player\_id" : [ {  
> "value" : "121347",  
> "displayName" : "Alex Rodriguez"  
> } ],  
> "team\_id" : [ {  
> "value" : "147",  
> "displayName" : "New York Yankees"  
> } ]  
> }
> 
> I guess, this is probably not there right now. Would it be possible to  
> add this as a feature request or is it too much of a hassle?
> 
> Thanks  
> Diptamay

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 4, 2010, 8:55am UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513/3 "2010-11-04T08:55:51Z")

</div>

Added `path_match` to `dynamic_template`:  
[Mapper: Add `path_match` for full object navigation path matching · Issue #476 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/476).

On Thu, Nov 4, 2010 at 1:20 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> There is the dynamic templates feature:  
> [http://www.elasticsearch.com/docs/elasticsearch/mapping/root\_object\_type/#dynamic\_templates](http://www.elasticsearch.com/docs/elasticsearch/mapping/root_object_type/#dynamic_templates),  
> but it can only be defined on the root object mapping, so no notion of  
> applying (matching) the template only for specific objects (like tags in  
> your case). But, it can be easily added by adding, on top of `match`, also  
> `path_match`, which will match on the current object "path", in your case  
> its tags. You can open a feature for it.
> 
> -shay.banon
> 
> On Thu, Nov 4, 2010 at 12:57 AM, diptamay [diptamay@gmail.com](mailto:diptamay@gmail.com) wrote:
> 
> > Hi Shay
> > 
> > I have documents of this type as listed under  
> > [661688’s gists · GitHub](https://gist.github.com/661688)
> > 
> > I was wondering if I could create mappings for fields that follow a  
> > certain pattern, as against ES determining dynamically how to index,  
> > store etc those fields. As an example, I want all the nested field  
> > values under "tags" section/object in the documents to all be treated  
> > as Strings. So I am looking to define a mapping like the following.  
> > Note the "\*" below under "tags".
> > 
> > {  
> > "video" : {  
> > "dynamic" : true,  
> > "enabled" : true,  
> > "date\_formats" : [  
> > "dateOptionalTime",  
> > "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"  
> > ],  
> > "\_source" : {  
> > "enabled" : true,  
> > "compress" : true,  
> > "name" : "\_source"  
> > },  
> > "properties" : {  
> > "itemType" : {  
> > "store" : "yes",  
> > "type" : "string"  
> > },  
> > "userDate" : {  
> > "store" : "yes",  
> > "format" : "dateOptionalTime",  
> > "type" : "date"  
> > },  
> > "tags" : {  
> > "properties" : {  
> > "\*" : {  
> > "properties" : {  
> > "value" : {  
> > "type" : "string"  
> > },  
> > "displayName" : {  
> > "type" : "string"  
> > }  
> > },  
> > "type" : "object"  
> > }  
> > }  
> > }  
> > },  
> > "\_all" : {  
> > "enabled" : true,  
> > "store" : "no",  
> > "term\_vector" : "no"  
> > },  
> > "type" : "object"  
> > }  
> > }
> > 
> > So whenever, a document would have, something like the following tags  
> > object, all the object values listed under combined\_media\_state/  
> > player\_id/team\_id, would be treated as strings as against dynamically  
> > decided by ES like integer for player\_id.value
> > 
> > "tags" : {  
> > "combined\_media\_state" : [ {  
> > "value" : "MEDIA\_ON",  
> > "displayName" : "MEDIA\_ON"  
> > } ],  
> > "weight" : [ {  
> > "value" : "1",  
> > "displayName" : "1"  
> > } ],  
> > "subject" : [ {  
> > "value" : "MLBCOM\_FEATURE",  
> > "displayName" : "MLBCOM\_FEATURE"  
> > } ],  
> > "mlbtax" : [ {  
> > "value" : "mm\_hightlight\_reel",  
> > "displayName" : "highlight reel"  
> > }, {  
> > "value" : "home\_run",  
> > "displayName" : "home run"  
> > } ],  
> > "player\_id" : [ {  
> > "value" : "121347",  
> > "displayName" : "Alex Rodriguez"  
> > } ],  
> > "team\_id" : [ {  
> > "value" : "147",  
> > "displayName" : "New York Yankees"  
> > } ]  
> > }
> > 
> > I guess, this is probably not there right now. Would it be possible to  
> > add this as a feature request or is it too much of a hassle?
> > 
> > Thanks  
> > Diptamay

---

<div class="post-metadata">

**Author:** ![Diptamay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diptamay/32/2805_2.png) [@Diptamay](https://discuss.elastic.co/u/Diptamay)\
**Post date:** [November 4, 2010, 3:36pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513/4 "2010-11-04T15:36:13Z")

</div>

Awesome. Thanks!

On Nov 4, 4:55 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Added `path_match` to `dynamic_template`:[Mapper: Add `path_match` for full object navigation path matching · Issue #476 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/476).
> 
> On Thu, Nov 4, 2010 at 1:20 AM, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com)wrote:
> 
> > There is the dynamic templates feature:  
> > [http://www.elasticsearch.com/docs/elasticsearch/mapping/root\_object\_t](http://www.elasticsearch.com/docs/elasticsearch/mapping/root_object_t)...,  
> > but it can only be defined on the root object mapping, so no notion of  
> > applying (matching) the template only for specific objects (like tags in  
> > your case). But, it can be easily added by adding, on top of `match`, also  
> > `path_match`, which will match on the current object "path", in your case  
> > its tags. You can open a feature for it.
> 
> > -shay.banon
> 
> > On Thu, Nov 4, 2010 at 12:57 AM, diptamay [dipta...@gmail.com](mailto:dipta...@gmail.com) wrote:
> 
> > > Hi Shay
> 
> > > I have documents of this type as listed under  
> > > [661688’s gists · GitHub](https://gist.github.com/661688)
> 
> > > I was wondering if I could create mappings for fields that follow a  
> > > certain pattern, as against ES determining dynamically how to index,  
> > > store etc those fields. As an example, I want all the nested field  
> > > values under "tags" section/object in the documents to all be treated  
> > > as Strings. So I am looking to define a mapping like the following.  
> > > Note the "\*" below under "tags".
> 
> > > {  
> > > "video" : {  
> > > "dynamic" : true,  
> > > "enabled" : true,  
> > > "date\_formats" : [  
> > > "dateOptionalTime",  
> > > "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"  
> > > ],  
> > > "\_source" : {  
> > > "enabled" : true,  
> > > "compress" : true,  
> > > "name" : "\_source"  
> > > },  
> > > "properties" : {  
> > > "itemType" : {  
> > > "store" : "yes",  
> > > "type" : "string"  
> > > },  
> > > "userDate" : {  
> > > "store" : "yes",  
> > > "format" : "dateOptionalTime",  
> > > "type" : "date"  
> > > },  
> > > "tags" : {  
> > > "properties" : {  
> > > "\*" : {  
> > > "properties" : {  
> > > "value" : {  
> > > "type" : "string"  
> > > },  
> > > "displayName" : {  
> > > "type" : "string"  
> > > }  
> > > },  
> > > "type" : "object"  
> > > }  
> > > }  
> > > }  
> > > },  
> > > "\_all" : {  
> > > "enabled" : true,  
> > > "store" : "no",  
> > > "term\_vector" : "no"  
> > > },  
> > > "type" : "object"  
> > > }  
> > > }
> 
> > > So whenever, a document would have, something like the following tags  
> > > object, all the object values listed under combined\_media\_state/  
> > > player\_id/team\_id, would be treated as strings as against dynamically  
> > > decided by ES like integer for player\_id.value
> 
> > > "tags" : {  
> > > "combined\_media\_state" : [ {  
> > > "value" : "MEDIA\_ON",  
> > > "displayName" : "MEDIA\_ON"  
> > > } ],  
> > > "weight" : [ {  
> > > "value" : "1",  
> > > "displayName" : "1"  
> > > } ],  
> > > "subject" : [ {  
> > > "value" : "MLBCOM\_FEATURE",  
> > > "displayName" : "MLBCOM\_FEATURE"  
> > > } ],  
> > > "mlbtax" : [ {  
> > > "value" : "mm\_hightlight\_reel",  
> > > "displayName" : "highlight reel"  
> > > }, {  
> > > "value" : "home\_run",  
> > > "displayName" : "home run"  
> > > } ],  
> > > "player\_id" : [ {  
> > > "value" : "121347",  
> > > "displayName" : "Alex Rodriguez"  
> > > } ],  
> > > "team\_id" : [ {  
> > > "value" : "147",  
> > > "displayName" : "New York Yankees"  
> > > } ]  
> > > }
> 
> > > I guess, this is probably not there right now. Would it be possible to  
> > > add this as a feature request or is it too much of a hassle?
> 
> > > Thanks  
> > > Diptamay

---

<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 6, 2017, 4:17am UTC](https://discuss.elastic.co/t/is-it-possible-to-create-mapping-for-fields-following-a-pattern-or-wildcard/3513/5 "2017-07-06T04:17:11Z")

</div>


