POST'ing Search Template as REST API causes Elastic to fail on start

I'm using Elasticsearch 5.3.0, with java version "1.8.0_121", on Linux.
Also confirmed the same behavior with latest commit of 5.x and master branch.
Is this an intended behavior?

According to Pre Registered Templates, we can POST search template using REST API.
It works as expected.
However, when we restart the Elasticsearch after registering the template, it throws an exception.

Here's the step to reproduce.

  1. Download elasticsearch-5.3.0.tar.gz from official site, and unarchive it.
  2. Run elasticsearch using ./bin/elasticsearch
  3. Post search template using following command:
curl -H 'Content-Type:application/json' -X POST 'http://localhost:9200/_search/template/this_is_a_test' --data '{"template":{"query":{"match":{"title": "{{query_string}}"}}}}'

it returns

  1. Quit Elasticsearch using Ctrl+C

  2. Start Elasticsearch using ./bin/elasticsearch

  3. The server fails to start with following stacktrace (only showing partial log):

[2017-04-17T17:55:36,116][ERROR][o.e.g.GatewayMetaState   ] [0i1Lvk1] failed to read local state, exiting...
org.elasticsearch.ElasticsearchException: failed to read [id:1, legacy:false, file:/home/my_user/Downloads/elasticsearch-5.3.0/data/nodes/0/_state/]
	at org.elasticsearch.ExceptionsHelper.maybeThrowRuntimeAndSuppress( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.gateway.MetaStateService.loadGlobalState( ~[elasticsearch-5.3.0.jar:5.3.0]
Caused by: failed to read [id:1, legacy:false, file:/home/my_user/Downloads/elasticsearch-5.3.0/data/nodes/0/_state/]
	at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState( ~[elasticsearch-5.3.0.jar:5.3.0]
	... 46 more
Caused by: org.elasticsearch.common.ParsingException: [stored script source] failed to parse field [options]
	at org.elasticsearch.common.xcontent.ObjectParser.parseValue( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.common.xcontent.ObjectParser.parseSub( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.common.xcontent.ObjectParser.parse( ~[elasticsearch-5.3.0.jar:5.3.0]
	... 46 more
Caused by: java.lang.IllegalArgumentException: content_type cannot be user-specified
	at org.elasticsearch.script.StoredScriptSource$Builder.setOptions( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.script.StoredScriptSource$Builder.access$100( ~[elasticsearch-5.3.0.jar:5.3.0]
	at org.elasticsearch.script.StoredScriptSource.lambda$static$4( ~[elasticsearch-5.3.0.jar:5.3.0]
	... 46 more
1 Like

I am also getting the same exception

I am also getting the same exception +1

This is indeed a bug and we are currently looking into it. You can track the progress here:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.