# Index Templates API - Source

**URL:** <https://discuss.elastic.co/t/index-templates-api-source/7312>\
**Category:** Elasticsearch\
**Created:** [April 12, 2012, 4:30pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312 "2012-04-12T16:30:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Huray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_huray/32/2921_2.png) [@Nicolas\_Huray](https://discuss.elastic.co/u/Nicolas_Huray)\
**Post date:** [April 12, 2012, 4:30pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/1 "2012-04-12T16:30:10Z")

</div>

Hi Shay,

Is there's a way with the Java client API to create a template and set the  
source like that :

PutIndexTemplateResponse response = client.admin().indices()  
.preparePutTemplate("twitter\_template").  
.setSource(sourceTemplate)  
.execute()  
.actionGet();

where source is a json object like :

{  
"template" : "te\*",  
"settings" : {  
"number\_of\_shards" : 1  
},  
"mappings" : {  
"type1" : {  
"\_source" : { "enabled" : false }  
}  
}  
}

instead to set setting, mappings ... like that :

PutIndexTemplateResponse response = client.admin().indices()  
.preparePutTemplate("twitter\_template")  
.setTemplate("twitter\*")  
.addMapping("tweet", sourceMapping)  
.setSettings(sourceSettings)  
.execute()  
.actionGet();

Thank you in advance for your response

---

<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:** [April 13, 2012, 12:28pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/2 "2012-04-13T12:28:14Z")

</div>

No, there isn't a way to do it, but we can support it if needed (thats what  
the REST endpoint does).

On Thu, Apr 12, 2012 at 7:30 PM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:

> Hi Shay,
> 
> Is there's a way with the Java client API to create a template and set the  
> source like that :
> 
> PutIndexTemplateResponse response = client.admin().indices()  
> .preparePutTemplate("twitter\_template").  
> .setSource(sourceTemplate)  
> .execute()  
> .actionGet();
> 
> where source is a json object like :
> 
> {  
> "template" : "te\*",  
> "settings" : {  
> "number\_of\_shards" : 1  
> },  
> "mappings" : {  
> "type1" : {  
> "\_source" : { "enabled" : false }  
> }  
> }  
> }
> 
> instead to set setting, mappings ... like that :
> 
> PutIndexTemplateResponse response = client.admin().indices()  
> .preparePutTemplate("twitter\_template")  
> .setTemplate("twitter\*")  
> .addMapping("tweet", sourceMapping)  
> .setSettings(sourceSettings)  
> .execute()  
> .actionGet();
> 
> Thank you in advance for your response

---

<div class="post-metadata">

**Author:** ![Nicolas\_Huray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_huray/32/2921_2.png) [@Nicolas\_Huray](https://discuss.elastic.co/u/Nicolas_Huray)\
**Post date:** [April 13, 2012, 10:47pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/3 "2012-04-13T22:47:10Z")

</div>

Hi Shay,

Thank you for your response. I think I'll submit you a pull request if I  
had a little time for that.

Le vendredi 13 avril 2012 14:28:14 UTC+2, kimchy a écrit :

> No, there isn't a way to do it, but we can support it if needed (thats  
> what the REST endpoint does).
> 
> On Thu, Apr 12, 2012 at 7:30 PM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > Is there's a way with the Java client API to create a template and set  
> > the source like that :
> > 
> > PutIndexTemplateResponse response = client.admin().indices()  
> > .preparePutTemplate("twitter\_template").  
> > .setSource(sourceTemplate)  
> > .execute()  
> > .actionGet();
> > 
> > where source is a json object like :
> > 
> > {  
> > "template" : "te\*",  
> > "settings" : {  
> > "number\_of\_shards" : 1  
> > },  
> > "mappings" : {  
> > "type1" : {  
> > "\_source" : { "enabled" : false }  
> > }  
> > }  
> > }
> > 
> > instead to set setting, mappings ... like that :
> > 
> > PutIndexTemplateResponse response = client.admin().indices()  
> > .preparePutTemplate("twitter\_template")  
> > .setTemplate("twitter\*")  
> > .addMapping("tweet", sourceMapping)  
> > .setSettings(sourceSettings)  
> > .execute()  
> > .actionGet();
> > 
> > Thank you in advance for your response

---

<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:** [April 14, 2012, 5:19pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/4 "2012-04-14T17:19:22Z")

</div>

Can you open an issue just in case? We basically need to move the parsing  
logic from the rest put index template method into a "setSource" method on  
the PutIndexTemplateRequest.

On Sat, Apr 14, 2012 at 1:47 AM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:

> Hi Shay,
> 
> Thank you for your response. I think I'll submit you a pull request if I  
> had a little time for that.
> 
> Le vendredi 13 avril 2012 14:28:14 UTC+2, kimchy a écrit :
> 
> > No, there isn't a way to do it, but we can support it if needed (thats  
> > what the REST endpoint does).
> > 
> > On Thu, Apr 12, 2012 at 7:30 PM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:
> > 
> > > Hi Shay,
> > > 
> > > Is there's a way with the Java client API to create a template and set  
> > > the source like that :
> > > 
> > > PutIndexTemplateResponse response = client.admin().indices()  
> > > .preparePutTemplate("twitter\_\*\*template").  
> > > .setSource(sourceTemplate)  
> > > .execute()  
> > > .actionGet();
> > > 
> > > where source is a json object like :
> > > 
> > > {  
> > > "template" : "te\*",  
> > > "settings" : {  
> > > "number\_of\_shards" : 1  
> > > },  
> > > "mappings" : {  
> > > "type1" : {  
> > > "\_source" : { "enabled" : false }  
> > > }  
> > > }  
> > > }
> > > 
> > > instead to set setting, mappings ... like that :
> > > 
> > > PutIndexTemplateResponse response = client.admin().indices()  
> > > .preparePutTemplate("twitter\_\*_template")  
> > > .setTemplate("twitter_")  
> > > .addMapping("tweet", sourceMapping)  
> > > .setSettings(sourceSettings)  
> > > .execute()  
> > > .actionGet();
> > > 
> > > Thank you in advance for your response

---

<div class="post-metadata">

**Author:** ![Nicolas\_Huray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_huray/32/2921_2.png) [@Nicolas\_Huray](https://discuss.elastic.co/u/Nicolas_Huray)\
**Post date:** [April 15, 2012, 11:02am UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/5 "2012-04-15T11:02:30Z")

</div>

Hi Shay,

I've just submit you a pull request to fix this issue :

> <https://github.com/elastic/elasticsearch/pull/1861>
>
> Hi Shay,
> 
> This is a pull request to fix issue #1860 regarding the template API.
> …
> Cheers,
> 
> Nicolas

Regards,

Le samedi 14 avril 2012 19:19:22 UTC+2, kimchy a écrit :

> Can you open an issue just in case? We basically need to move the parsing  
> logic from the rest put index template method into a "setSource" method on  
> the PutIndexTemplateRequest.
> 
> On Sat, Apr 14, 2012 at 1:47 AM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > Thank you for your response. I think I'll submit you a pull request if I  
> > had a little time for that.
> > 
> > Le vendredi 13 avril 2012 14:28:14 UTC+2, kimchy a écrit :
> > 
> > > No, there isn't a way to do it, but we can support it if needed (thats  
> > > what the REST endpoint does).
> > > 
> > > On Thu, Apr 12, 2012 at 7:30 PM, Nicolas Huray [nicolas.huray@gmail.com](mailto:nicolas.huray@gmail.com)wrote:
> > > 
> > > > Hi Shay,
> > > > 
> > > > Is there's a way with the Java client API to create a template and set  
> > > > the source like that :
> > > > 
> > > > PutIndexTemplateResponse response = client.admin().indices()  
> > > > .preparePutTemplate("twitter\_\*\*template").  
> > > > .setSource(sourceTemplate)  
> > > > .execute()  
> > > > .actionGet();
> > > > 
> > > > where source is a json object like :
> > > > 
> > > > {  
> > > > "template" : "te\*",  
> > > > "settings" : {  
> > > > "number\_of\_shards" : 1  
> > > > },  
> > > > "mappings" : {  
> > > > "type1" : {  
> > > > "\_source" : { "enabled" : false }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > instead to set setting, mappings ... like that :
> > > > 
> > > > PutIndexTemplateResponse response = client.admin().indices()  
> > > > .preparePutTemplate("twitter\_\*_template")  
> > > > .setTemplate("twitter_")  
> > > > .addMapping("tweet", sourceMapping)  
> > > > .setSettings(sourceSettings)  
> > > > .execute()  
> > > > .actionGet();
> > > > 
> > > > Thank you in advance for your response

---

<div class="post-metadata">

**Author:** ![thaidoan](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@thaidoan](https://discuss.elastic.co/u/thaidoan)\
**Post date:** [May 1, 2012, 2:00pm UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/6 "2012-05-01T14:00:52Z")

</div>

Hi Shay,

Was the issue fixed in the latest version (0.19.3), yet?

Regards, Thai

---

<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, 3:30am UTC](https://discuss.elastic.co/t/index-templates-api-source/7312/7 "2017-07-06T03:30:29Z")

</div>


