Здравствуйте!
Пытаюсь разобраться со script engine.
Написал такой вот минимальный пример.
private static class MyScriptEngine implements ScriptEngineService {
@Override
public String getType() {
return "scripts";
}
@Override
public Function<Map<String,Object>, SearchScript> compile(String scriptName, String scriptSource, Map<String, String> params) {
return p -> new SearchScript() {
@Override
public boolean needsScores() {
return false;
}
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
return new AbstractSearchScript() {
@Override
public Object run() {
System.out.println("Booo");
return 1;
}
};
}
};
}
@Override
@SuppressWarnings("unchecked")
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> params) {
Function<Map<String,Object>, SearchScript> scriptFactory = (Function<Map<String,Object>,SearchScript>) compiledScript.compiled();
return scriptFactory.apply(params);
}
@Override
public ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> params) {
throw new UnsupportedOperationException();
}
@Override
public boolean isInlineScriptEnabled() {
return true;
}
@Override
public void close() {
}
}
пытаюсь получить скриптовое поле
{
"_source": false,
"query": {
},
"script_fields": {
"test": {
"script": {
"source": "_",
"lang": "scripts",
"params": {
}
}
}
}
}
но получаю NPE.
[2017-10-20T19:47:42,171][DEBUG][o.e.a.s.TransportSearchAction] [8nIomLL] [4] Failed to execute fetch phase org.elasticsearch.transport.RemoteTransportException: [8nIomLL][127.0.0.1:9300][indices:data/read/search[phase/fetch/id]] Caused by: java.lang.NullPointerException at org.elasticsearch.script.AbstractSearchScript.setDocument(AbstractSearchScript.java:115) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase.hitExecute(ScriptFieldsFetchSubPhase.java:47) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:165) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:426) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.action.search.SearchTransportService$12.messageReceived(SearchTransportService.java:407) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.action.search.SearchTransportService$12.messageReceived(SearchTransportService.java:404) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:644) [elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) [elasticsearch-5.6.3.jar:5.6.3] at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.6.3.jar:5.6.3] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_112] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_112] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_112]Что я делаю не так?