Fixing template rendering after changes in master

This commit is contained in:
Christoph Büscher 2017-05-30 15:21:02 +02:00
parent 3d6fb4eb0b
commit 5a4124d4fb
6 changed files with 9 additions and 16 deletions

View File

@ -22,7 +22,3 @@ esplugin {
classname 'org.elasticsearch.index.rankeval.RankEvalPlugin' classname 'org.elasticsearch.index.rankeval.RankEvalPlugin'
} }
integTestCluster {
setting 'script.inline', 'true'
setting 'script.stored', 'true'
}

View File

@ -26,19 +26,19 @@ import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.template.CompiledTemplate;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -97,10 +97,10 @@ public class TransportRankEvalAction
ratedRequests.size()); ratedRequests.size());
Map<String, Exception> errors = new ConcurrentHashMap<>(ratedRequests.size()); Map<String, Exception> errors = new ConcurrentHashMap<>(ratedRequests.size());
Map<String, CompiledScript> scriptsWithoutParams = new HashMap<>(); Map<String, CompiledTemplate> scriptsWithoutParams = new HashMap<>();
for (Entry<String, Script> entry : qualityTask.getTemplates().entrySet()) { for (Entry<String, Script> entry : qualityTask.getTemplates().entrySet()) {
scriptsWithoutParams.put(entry.getKey(), scriptsWithoutParams.put(entry.getKey(),
scriptService.compile(entry.getValue(), ScriptContext.Standard.SEARCH)); scriptService.compileTemplate(entry.getValue(), ExecutableScript.CONTEXT));
} }
for (RatedRequest ratedRequest : ratedRequests) { for (RatedRequest ratedRequest : ratedRequests) {
@ -110,10 +110,9 @@ public class TransportRankEvalAction
if (ratedSearchSource == null) { if (ratedSearchSource == null) {
Map<String, Object> params = ratedRequest.getParams(); Map<String, Object> params = ratedRequest.getParams();
String templateId = ratedRequest.getTemplateId(); String templateId = ratedRequest.getTemplateId();
CompiledScript compiled = scriptsWithoutParams.get(templateId); CompiledTemplate compiled = scriptsWithoutParams.get(templateId);
BytesReference resolvedRequest = (BytesReference) (scriptService String resolvedRequest = compiled.run(params);
.executable(compiled, params).run()); try (XContentParser subParser = createParser(namedXContentRegistry, new BytesArray(resolvedRequest),
try (XContentParser subParser = createParser(namedXContentRegistry, resolvedRequest,
XContentType.JSON)) { XContentType.JSON)) {
QueryParseContext parseContext = new QueryParseContext(subParser); QueryParseContext parseContext = new QueryParseContext(subParser);
ratedSearchSource = SearchSourceBuilder.fromXContent(parseContext); ratedSearchSource = SearchSourceBuilder.fromXContent(parseContext);

View File

@ -25,8 +25,6 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import java.io.IOException;
public class SmokeTestRankEvalWithMustacheYAMLTestSuiteIT extends ESClientYamlSuiteTestCase { public class SmokeTestRankEvalWithMustacheYAMLTestSuiteIT extends ESClientYamlSuiteTestCase {
public SmokeTestRankEvalWithMustacheYAMLTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { public SmokeTestRankEvalWithMustacheYAMLTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
@ -34,7 +32,7 @@ public class SmokeTestRankEvalWithMustacheYAMLTestSuiteIT extends ESClientYamlSu
} }
@ParametersFactory @ParametersFactory
public static Iterable<Object[]> parameters() throws IOException { public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters(); return ESClientYamlSuiteTestCase.createParameters();
} }