当前位置: 首页>>代码示例>>Java>>正文


Java ExecutableScript.run方法代码示例

本文整理汇总了Java中org.elasticsearch.script.ExecutableScript.run方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableScript.run方法的具体用法?Java ExecutableScript.run怎么用?Java ExecutableScript.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.script.ExecutableScript的用法示例。


在下文中一共展示了ExecutableScript.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exec

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
/** Compiles and returns the result of {@code script} with access to {@code vars} and compile-time parameters */
public Object exec(String script, Map<String, Object> vars, Map<String,String> compileParams, Scorer scorer, boolean picky) {
    // test for ambiguity errors before running the actual script if picky is true
    if (picky) {
        ScriptInterface scriptInterface = new ScriptInterface(GenericElasticsearchScript.class);
        CompilerSettings pickySettings = new CompilerSettings();
        pickySettings.setPicky(true);
        pickySettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(scriptEngineSettings()));
        Walker.buildPainlessTree(scriptInterface, getTestName(), script, pickySettings, null);
    }
    // test actual script execution
    Object object = scriptEngine.compile(null, script, compileParams);
    CompiledScript compiled = new CompiledScript(ScriptType.INLINE, getTestName(), "painless", object);
    ExecutableScript executableScript = scriptEngine.executable(compiled, vars);
    if (scorer != null) {
        ((ScorerAware)executableScript).setScorer(scorer);
    }
    return executableScript.run();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ScriptTestCase.java

示例2: testChangingVarsCrossExecution1

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
public void testChangingVarsCrossExecution1() {
    Map<String, Object> vars = new HashMap<>();
    Map<String, Object> ctx = new HashMap<>();
    vars.put("ctx", ctx);

    Object compiledScript = scriptEngine.compile(null,
            "return ctx.value;", Collections.emptyMap());
    ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptType.INLINE,
            "testChangingVarsCrossExecution1", "painless", compiledScript), vars);

    ctx.put("value", 1);
    Object o = script.run();
    assertEquals(1, ((Number) o).intValue());

    ctx.put("value", 2);
    o = script.run();
    assertEquals(2, ((Number) o).intValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ScriptEngineTests.java

示例3: createInternal

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Override
public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData) throws IOException {
    if (collectsFromSingleBucket == false) {
        return asMultiBucketAggregator(this, context, parent);
    }
    Map<String, Object> params = this.params;
    if (params != null) {
        params = deepCopyParams(params, context);
    } else {
        params = new HashMap<>();
        params.put("_agg", new HashMap<String, Object>());
    }

    final ExecutableScript initScript = this.initScript.apply(params);
    final SearchScript mapScript = this.mapScript.apply(params);
    final ExecutableScript combineScript = this.combineScript.apply(params);

    final Script reduceScript = deepCopyScript(this.reduceScript, context);
    if (initScript != null) {
        initScript.run();
    }
    return new ScriptedMetricAggregator(name, mapScript,
            combineScript, reduceScript, params, context, parent,
            pipelineAggregators, metaData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ScriptedMetricAggregatorFactory.java

示例4: parse

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
/**
 * Parses the template query replacing template parameters with provided
 * values. Handles both submitting the template as part of the request as
 * well as referencing only the template name.
 *
 * @param parseContext
 *            parse context containing the templated query.
 */
@Override
@Nullable
public Query parse(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    Template template = parse(parser, parseContext.parseFieldMatcher());
    ExecutableScript executable = this.scriptService.executable(template, ScriptContext.Standard.SEARCH, SearchContext.current(), Collections.<String, String>emptyMap());

    BytesReference querySource = (BytesReference) executable.run();

    try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) {
        final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParserService());
        context.reset(qSourceParser);
        return context.parseInnerQuery();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:TemplateQueryParser.java

示例5: transformSourceAsMap

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> transformSourceAsMap(Map<String, Object> sourceAsMap) {
    try {
        // We use the ctx variable and the _source name to be consistent with the update api.
        ExecutableScript executable = scriptService.executable(script, ScriptContext.Standard.MAPPING, null, Collections.<String, String>emptyMap());
        Map<String, Object> ctx = new HashMap<>(1);
        ctx.put("_source", sourceAsMap);
        executable.setNextVar("ctx", ctx);
        executable.run();
        ctx = (Map<String, Object>) executable.unwrap(ctx);
        return (Map<String, Object>) ctx.get("_source");
    } catch (Exception e) {
        throw new IllegalArgumentException("failed to execute script", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:DocumentMapper.java

示例6: testChangingVarsCrossExecution1

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Test
public void testChangingVarsCrossExecution1() {
    Map<String, Object> vars = new HashMap<String, Object>();
    Map<String, Object> ctx = new HashMap<String, Object>();
    vars.put("ctx", ctx);
    Object compiledScript = se.compile("ctx.value");

    ExecutableScript script = se.executable(compiledScript, vars);
    ctx.put("value", 1);
    Object o = script.run();
    assertThat(((Number) o).intValue(), equalTo(1));

    ctx.put("value", 2);
    o = script.run();
    assertThat(((Number) o).intValue(), equalTo(2));
}
 
开发者ID:jprante,项目名称:elasticsearch-lang-javascript-nashorn,代码行数:17,代码来源:NashornScriptEngineTests.java

示例7: execute

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
/**
 * Executes the script with the Ingest document in context.
 *
 * @param document The Ingest document passed into the script context under the "ctx" object.
 */
@Override
public void execute(IngestDocument document) {
    ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.INGEST);
    executableScript.setNextVar("ctx",  document.getSourceAndMetadata());
    executableScript.run();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:ScriptProcessor.java

示例8: testJsonEscapeEncoder

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
public void testJsonEscapeEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = randomBoolean() ? singletonMap(Script.CONTENT_TYPE_OPTION, JSON_MIME_TYPE) : emptyMap();

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "a \"value\""));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"a \\\"value\\\"\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java

示例9: testDefaultEncoder

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
public void testDefaultEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, PLAIN_TEXT_MIME_TYPE);

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "a \"value\""));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"a \"value\"\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java

示例10: testUrlEncoder

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
public void testUrlEncoder() {
    final ScriptEngineService engine = new MustacheScriptEngineService();
    final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, X_WWW_FORM_URLENCODED_MIME_TYPE);

    Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
    CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);

    ExecutableScript executable = engine.executable(compiled, singletonMap("value", "tilde~ AND date:[2016 FROM*]"));
    BytesReference result = (BytesReference) executable.run();
    assertThat(result.utf8ToString(), equalTo("{\"field\": \"tilde%7E+AND+date%3A%5B2016+FROM*%5D\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomMustacheFactoryTests.java

示例11: testChangingVarsCrossExecution2

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
public void testChangingVarsCrossExecution2() {
    Map<String, Object> vars = new HashMap<>();
    Object compiledScript = scriptEngine.compile(null, "return params['value'];", Collections.emptyMap());

    ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptType.INLINE,
            "testChangingVarsCrossExecution2", "painless", compiledScript), vars);

    script.setNextVar("value", 1);
    Object value = script.run();
    assertEquals(1, ((Number)value).intValue());

    script.setNextVar("value", 2);
    value = script.run();
    assertEquals(2, ((Number)value).intValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ScriptEngineTests.java

示例12: reduce

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Override
public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) {
    InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket> originalAgg =
            (InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket>) aggregation;
    List<? extends Bucket> buckets = originalAgg.getBuckets();

    CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.Standard.AGGS);
    List newBuckets = new ArrayList<>();
    for (Bucket bucket : buckets) {
        Map<String, Object> vars = new HashMap<>();
        if (script.getParams() != null) {
            vars.putAll(script.getParams());
        }
        for (Map.Entry<String, String> entry : bucketsPathsMap.entrySet()) {
            String varName = entry.getKey();
            String bucketsPath = entry.getValue();
            Double value = resolveBucketValue(originalAgg, bucket, bucketsPath, gapPolicy);
            vars.put(varName, value);
        }
        ExecutableScript executableScript = reduceContext.scriptService().executable(compiledScript, vars);
        Object scriptReturnValue = executableScript.run();
        final boolean keepBucket;
        // TODO: WTF!!!!!
        if ("expression".equals(script.getLang())) {
            double scriptDoubleValue = (double) scriptReturnValue;
            keepBucket = scriptDoubleValue == 1.0;
        } else {
            keepBucket = (boolean) scriptReturnValue;
        }
        if (keepBucket) {
            newBuckets.add(bucket);
        }
    }
    return originalAgg.create(newBuckets);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:BucketSelectorPipelineAggregator.java

示例13: compile

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Override
public Template compile(String template) {
    int mustacheStart = template.indexOf("{{");
    int mustacheEnd = template.indexOf("}}");
    if (mustacheStart != -1 && mustacheEnd != -1 && mustacheStart < mustacheEnd) {
        Script script = new Script(ScriptType.INLINE, "mustache", template, Collections.emptyMap());
        CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.INGEST);
        return new Template() {
            @Override
            public String execute(Map<String, Object> model) {
                ExecutableScript executableScript = scriptService.executable(compiledScript, model);
                Object result = executableScript.run();
                if (result instanceof BytesReference) {
                    return ((BytesReference) result).utf8ToString();
                }
                return String.valueOf(result);
            }

            @Override
            public String getKey() {
                return template;
            }
        };
    } else {
        return new StringTemplate(template);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:InternalTemplateService.java

示例14: executeScript

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
private Map<String, Object> executeScript(Script script, Map<String, Object> ctx) {
    try {
        if (scriptService != null) {
            ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.UPDATE);
            executableScript.setNextVar("ctx", ctx);
            executableScript.run();
            // we need to unwrap the ctx...
            ctx = (Map<String, Object>) executableScript.unwrap(ctx);
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("failed to execute script", e);
    }
    return ctx;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:UpdateHelper.java

示例15: reduce

import org.elasticsearch.script.ExecutableScript; //导入方法依赖的package包/类
@Override
public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) {
    InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket> originalAgg = (InternalMultiBucketAggregation<InternalMultiBucketAggregation, InternalMultiBucketAggregation.InternalBucket>) aggregation;
    List<? extends Bucket> buckets = originalAgg.getBuckets();

    CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.Standard.AGGS, reduceContext, Collections.<String, String>emptyMap());
    List newBuckets = new ArrayList<>();
    for (Bucket bucket : buckets) {
        Map<String, Object> vars = new HashMap<>();
        if (script.getParams() != null) {
            vars.putAll(script.getParams());
        }
        for (Map.Entry<String, String> entry : bucketsPathsMap.entrySet()) {
            String varName = entry.getKey();
            String bucketsPath = entry.getValue();
            Double value = resolveBucketValue(originalAgg, bucket, bucketsPath, gapPolicy);
            vars.put(varName, value);
        }
        ExecutableScript executableScript = reduceContext.scriptService().executable(compiledScript, vars);
        Object scriptReturnValue = executableScript.run();
        final boolean keepBucket;
        // TODO: WTF!!!!!
        if ("expression".equals(script.getLang())) {
            double scriptDoubleValue = (double) scriptReturnValue;
            keepBucket = scriptDoubleValue == 1.0;
        } else {
            keepBucket = (boolean) scriptReturnValue;
        }
        if (keepBucket) {
            newBuckets.add(bucket);
        }
    }
    return originalAgg.create(newBuckets);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:BucketSelectorPipelineAggregator.java


注:本文中的org.elasticsearch.script.ExecutableScript.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。