# Cannot load search template registered with REST API

**URL:** <https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755>\
**Category:** Elasticsearch\
**Created:** [July 1, 2015, 8:05pm UTC](https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755 "2015-07-01T20:05:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeppe/32/3493_2.png) [@Jeppe](https://discuss.elastic.co/u/Jeppe)\
**Post date:** [July 1, 2015, 8:05pm UTC](https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755/1 "2015-07-01T20:05:28Z")

</div>

Hi,

I have a problem when loading a search template which has been registrered through the REST API. If the search template is placed in the /config/scrips/ folder there is no problem.

The template has been registrered via POST to: /\_search/template/templateName, and I can see that the template has been succesfully registered when I do a GET to: /\_search/template/templateName.

However, when I try to send a request that utilizes this search template I get an error. If have tried the following endpoints:  
POST: /\_search/template (the one from the documentation)  
POST: [index]/\_search/template  
POST: [index]/[type]/\_search/template

With this body:  
{  
"template": {  
"file": "templateName"  
},  
"params": {  
"userId" : "AU43nSoTZOSzwq\_2ZUA4",  
etc...  
}  
}

But it keeps returning this error:  
{  
"error": "SearchPhaseExecutionException[Failed to execute phase [query\_fetch], all shards failed; shardFailures {[UDBaJWKqQ5GpZedzLCtrFg][.scripts][0]: ElasticsearchIllegalArgumentException[Unable to find on disk script templateName]}]",  
"status": 400  
}

I cannot upload files to the ElasticSearch host that I'm using, so I need to register them via POST request. What am I missing?

Thanks in advance  
Jeppe

---

<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:** [July 2, 2015, 2:56am UTC](https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755/2 "2015-07-02T02:56:55Z")

</div>

`"file": "templateName"` refers to the file on disk. To use preregistered template you need to change it to `"id": "templateName"`

---

<div class="post-metadata">

**Author:** ![Jeppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeppe/32/3493_2.png) [@Jeppe](https://discuss.elastic.co/u/Jeppe)\
**Post date:** [July 2, 2015, 7:45am UTC](https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755/3 "2015-07-02T07:45:58Z")

</div>

Ahh thank you. Stupid mistake 🙂

---

<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, 12:04am UTC](https://discuss.elastic.co/t/cannot-load-search-template-registered-with-rest-api/24755/4 "2017-07-06T00:04:00Z")

</div>


