Cannot load search template registered with REST API

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

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

Ahh thank you. Stupid mistake :slight_smile: