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.
- Download
elasticsearch-5.3.0.tar.gz
from official site, and unarchive it. - Run elasticsearch using
./bin/elasticsearch
- 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
{"acknowledged":true}
-
Quit Elasticsearch using
Ctrl+C
-
Start Elasticsearch using
./bin/elasticsearch
-
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: java.io.IOException: failed to read [id:1, legacy:false, file:/home/my_user/Downloads/elasticsearch-5.3.0/data/nodes/0/_state/global-1.st]
at org.elasticsearch.ExceptionsHelper.maybeThrowRuntimeAndSuppress(ExceptionsHelper.java:150) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:334) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.gateway.MetaStateService.loadGlobalState(MetaStateService.java:113) ~[elasticsearch-5.3.0.jar:5.3.0]
Caused by: java.io.IOException: failed to read [id:1, legacy:false, file:/home/my_user/Downloads/elasticsearch-5.3.0/data/nodes/0/_state/global-1.st]
at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:327) ~[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(ObjectParser.java:369) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.common.xcontent.ObjectParser.parseSub(ObjectParser.java:378) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.common.xcontent.ObjectParser.parse(ObjectParser.java:169) ~[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(StoredScriptSource.java:127) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.script.StoredScriptSource$Builder.access$100(StoredScriptSource.java:87) ~[elasticsearch-5.3.0.jar:5.3.0]
at org.elasticsearch.script.StoredScriptSource.lambda$static$4(StoredScriptSource.java:163) ~[elasticsearch-5.3.0.jar:5.3.0]
... 46 more