# Registering default mappings and dynamic templates via Java Api

**URL:** <https://discuss.elastic.co/t/registering-default-mappings-and-dynamic-templates-via-java-api/10535>\
**Category:** Elasticsearch\
**Created:** [January 29, 2013, 7:27am UTC](https://discuss.elastic.co/t/registering-default-mappings-and-dynamic-templates-via-java-api/10535 "2013-01-29T07:27:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eg1](https://avatars.discourse-cdn.com/v4/letter/e/b38774/32.png) [@eg1](https://discuss.elastic.co/u/eg1)\
**Post date:** [January 29, 2013, 7:27am UTC](https://discuss.elastic.co/t/registering-default-mappings-and-dynamic-templates-via-java-api/10535/1 "2013-01-29T07:27:23Z")

</div>

Hi there,

I am trying to setup configuration on an embedded elasticsearch node that  
consists of dynamic templates and mappings for '_defaullt_'.  
I am using the following template that defines several dynamic templates  
and a mapping to enable "\_timestamp" on each type.

```
{
                "_default_" : {
                    "dynamic_templates" : [
                         {
                             "string_template" : {
                                 "match_mapping_type" : "string",
                                 "path_match" : "*.fulltext",
                                 "mapping" : {
                                      "type" : "multi_field",
                                     "fields" : {
                                         "{name}" : {"type": "string", 

```

"index" : "analyzed"  
},  
"untouched" : {  
"type": "string", "index"  
: "not\_analyzed""  
"}"  
}"  
}"  
}"  
}"  
,  
{"  
"string\_nonanalyzed\_template" : {  
"match\_mapping\_type" : "string",  
"path\_match" : "_",  
"mapping" : {  
"index" : "not\_analyzed",  
"type" : "string"  
, "include\_in\_all" : false  
}  
}  
}  
,  
{  
"long\_template" : {  
"match\_mapping\_type" : "long",  
"match" : "_",  
"mapping" : {  
"index" : "not\_analyzed",  
"type" : "long"  
, "include\_in\_all" : false  
}  
}  
}  
],  
"\_timestamp" : {  
""enabled" : true,  
""store": true  
}  
}  
}

I register it at index creation using the following Java Api call:

client.admin().indices().prepareCreate(getMandatoryTBox().getId()).addMapping("_default_",  
IndexServiceImpl.DYN\_TEMPLATE).execute().actionGet();

The dynamic templates are applied correctly to all types in the system.  
However the \_timestamp field does not show up when I look at the index in  
elasticsearch-head.  
What am I missing or doing wrong?  
Thanks a lot in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 2, 2013, 1:09am UTC](https://discuss.elastic.co/t/registering-default-mappings-and-dynamic-templates-via-java-api/10535/2 "2013-02-02T01:09:37Z")

</div>

Are all these extra quotes part of your template or it's just badly  
formatted email?

```
                                         "untouched" : {
                                             "type": "string", "index" 

```

: "not\_analyzed""  
"}"  
}"  
}"  
}"  
}"

If it's former, could you post clean mapping?

On Tuesday, January 29, 2013 2:27:23 AM UTC-5, eg wrote:

> Hi there,
> 
> I am trying to setup configuration on an embedded elasticsearch node that  
> consists of dynamic templates and mappings for '_defaullt_'.  
> I am using the following template that defines several dynamic templates  
> and a mapping to enable "\_timestamp" on each type.
> 
> ```
> {
> "_default_" : {
> "dynamic_templates" : [
> {
> "string_template" : {
> "match_mapping_type" : "string",
> "path_match" : "*.fulltext",
> "mapping" : {
> "type" : "multi_field",
> "fields" : {
> "{name}" : {"type": "string", 
> 
> ```
> 
> "index" : "analyzed"  
> },  
> "untouched" : {  
> "type": "string", "index"  
> : "not\_analyzed""  
> "}"  
> }"  
> }"  
> }"  
> }"  
> ,  
> {"  
> "string\_nonanalyzed\_template" : {  
> "match\_mapping\_type" : "string",  
> "path\_match" : "_",  
> "mapping" : {  
> "index" : "not\_analyzed",  
> "type" : "string"  
> , "include\_in\_all" : false  
> }  
> }  
> }  
> ,  
> {  
> "long\_template" : {  
> "match\_mapping\_type" : "long",  
> "match" : "_",  
> "mapping" : {  
> "index" : "not\_analyzed",  
> "type" : "long"  
> , "include\_in\_all" : false  
> }  
> }  
> }  
> ],  
> "\_timestamp" : {  
> ""enabled" : true,  
> ""store": true  
> }  
> }  
> }
> 
> I register it at index creation using the following Java Api call:
> 
> client.admin().indices().prepareCreate(getMandatoryTBox().getId()).addMapping("_default_",  
> IndexServiceImpl.DYN\_TEMPLATE).execute().actionGet();
> 
> The dynamic templates are applied correctly to all types in the system.  
> However the \_timestamp field does not show up when I look at the index in  
> elasticsearch-head.  
> What am I missing or doing wrong?  
> Thanks a lot in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:53am UTC](https://discuss.elastic.co/t/registering-default-mappings-and-dynamic-templates-via-java-api/10535/3 "2017-07-06T02:53:24Z")

</div>


