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


Java ScriptType类代码示例

本文整理汇总了Java中org.elasticsearch.script.ScriptType的典型用法代码示例。如果您正苦于以下问题:Java ScriptType类的具体用法?Java ScriptType怎么用?Java ScriptType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testUnmapped

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    SearchResponse response = client()
            .prepareSearch("idx_unmapped")
            .addAggregation(
                    histogram("histo")
                            .field(FIELD_1_NAME)
                            .interval(interval)
                            .subAggregation(sum("field2Sum").field(FIELD_2_NAME))
                            .subAggregation(sum("field3Sum").field(FIELD_3_NAME))
                            .subAggregation(sum("field4Sum").field(FIELD_4_NAME))
                            .subAggregation(
                                    bucketScript("seriesArithmetic",
                                            new Script(ScriptType.INLINE,
                                                CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
                                            "field2Sum", "field3Sum", "field4Sum")))
                            .execute().actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    assertThat(deriv.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:BucketScriptIT.java

示例2: testSearchRequestFail

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testSearchRequestFail() throws Exception {
    String query = "{ \"query\": {\"match_all\": {}}, \"size\" : \"{{my_size}}\"  }";

    SearchRequest searchRequest = new SearchRequest();
    searchRequest.indices("_all");

    expectThrows(Exception.class, () -> new SearchTemplateRequestBuilder(client())
            .setRequest(searchRequest)
            .setScript(query)
            .setScriptType(ScriptType.INLINE)
            .setScriptParams(randomBoolean() ? null : Collections.emptyMap())
            .get());

    SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client())
            .setRequest(searchRequest)
            .setScript(query)
            .setScriptType(ScriptType.INLINE)
            .setScriptParams(Collections.singletonMap("my_size", 1))
            .get();

    assertThat(searchResponse.getResponse().getHits().getHits().length, equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:SearchTemplateIT.java

示例3: testFailedMultiSearchWithWrongQueryWithFunctionScore

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testFailedMultiSearchWithWrongQueryWithFunctionScore() throws Exception {
    prepareData();

    logger.info("Start Testing failed multi search with a wrong query");

    MultiSearchResponse response = client().prepareMultiSearch()
            // Add custom score query with bogus script
            .add(client().prepareSearch("test").setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("nid", 1), new ScriptScoreFunctionBuilder(new Script(ScriptType.INLINE, "bar", "foo", Collections.emptyMap())))))
            .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("nid", 2)))
            .add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()))
            .execute().actionGet();
    assertThat(response.getResponses().length, equalTo(3));
    assertThat(response.getResponses()[0].getFailureMessage(), notNullValue());

    assertThat(response.getResponses()[1].getFailureMessage(), nullValue());
    assertThat(response.getResponses()[1].getResponse().getHits().getHits().length, equalTo(1));

    assertThat(response.getResponses()[2].getFailureMessage(), nullValue());
    assertThat(response.getResponses()[2].getResponse().getHits().getHits().length, equalTo(10));

    logger.info("Done Testing failed search");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TransportTwoNodesSearchIT.java

示例4: getElasticsearchCalendarFieldAggregation

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
private Collection<? extends AggregationBuilder> getElasticsearchCalendarFieldAggregation(CalendarFieldAggregation agg) {
    List<AggregationBuilder> aggs = new ArrayList<>();
    PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getPropertyName());
    if (propertyDefinition == null) {
        throw new MemgraphException("Could not find mapping for property: " + agg.getPropertyName());
    }
    Class propertyDataType = propertyDefinition.getDataType();
    for (String propertyName : getPropertyNames(agg.getPropertyName())) {
        String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName);
        String aggName = createAggregationName(agg.getAggregationName(), visibilityHash);
        if (propertyDataType == Date.class) {
            HistogramAggregationBuilder histAgg = AggregationBuilders.histogram(aggName);
            histAgg.interval(1);
            if (agg.getMinDocumentCount() != null) {
                histAgg.minDocCount(agg.getMinDocumentCount());
            } else {
                histAgg.minDocCount(1L);
            }
            Script script = new Script(
                    ScriptType.INLINE,
                    "painless",
                    getCalendarFieldAggregationScript(agg, propertyName),
                    ImmutableMap.of(
                            "tzId", agg.getTimeZone().getID(),
                            "fieldName", propertyName,
                            "calendarField", agg.getCalendarField())
            );
            histAgg.script(script);

            for (AggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) {
                histAgg.subAggregation(subAgg);
            }

            aggs.add(histAgg);
        } else {
            throw new MemgraphException("Only dates are supported for hour of day aggregations");
        }
    }
    return aggs;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:41,代码来源:ElasticsearchSearchQueryBase.java

示例5: testScriptScoresWithAgg

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testScriptScoresWithAgg() throws IOException {
    createIndex(INDEX);
    index(INDEX, TYPE, "1", jsonBuilder().startObject().field("dummy_field", 1).endObject());
    refresh();

    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get score value", Collections.emptyMap());

    SearchResponse response = client().search(
            searchRequest().source(
                    searchSource()
                            .query(functionScoreQuery(scriptFunction(script)))
                            .aggregation(terms("score_agg").script(script))
            )
    ).actionGet();
    assertSearchResponse(response);
    assertThat(response.getHits().getAt(0).getScore(), equalTo(1.0f));
    assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getKeyAsString(), equalTo("1.0"));
    assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getDocCount(), is(1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:FunctionScoreIT.java

示例6: prepareRequest

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    // Creates the render template request
    SearchTemplateRequest renderRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        renderRequest = RestSearchTemplateAction.parse(parser);
    }
    renderRequest.setSimulate(true);

    String id = request.param("id");
    if (id != null) {
        renderRequest.setScriptType(ScriptType.STORED);
        renderRequest.setScript(id);
    }

    return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestRenderSearchTemplateAction.java

示例7: testCancellationDuringQueryPhase

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testCancellationDuringQueryPhase() throws Exception {

        List<ScriptedBlockPlugin> plugins = initBlockFactory();
        indexTestData();

        logger.info("Executing search");
        ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test").setQuery(
            scriptQuery(new Script(
                ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
            .execute();

        awaitForBlock(plugins);
        cancelSearch(SearchAction.NAME);
        disableBlocks(plugins);
        logger.info("Segments {}", XContentHelper.toString(client().admin().indices().prepareSegments("test").get(), FORMAT_PARAMS));
        ensureSearchWasCancelled(searchResponse);
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SearchCancellationIT.java

示例8: testCancellationOfScrollSearches

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testCancellationOfScrollSearches() throws Exception {

        List<ScriptedBlockPlugin> plugins = initBlockFactory();
        indexTestData();

        logger.info("Executing search");
        ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test")
            .setScroll(TimeValue.timeValueSeconds(10))
            .setSize(5)
            .setQuery(
                scriptQuery(new Script(
                    ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
            .execute();

        awaitForBlock(plugins);
        cancelSearch(SearchAction.NAME);
        disableBlocks(plugins);
        SearchResponse response = ensureSearchWasCancelled(searchResponse);
        if (response != null) {
            // The response might not have failed on all shards - we need to clean scroll
            logger.info("Cleaning scroll with id {}", response.getScrollId());
            client().prepareClearScroll().addScrollId(response.getScrollId()).get();
        }
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:SearchCancellationIT.java

示例9: testUnmapped

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", Collections.emptyMap());

    SearchResponse response = client().prepareSearch("idx_unmapped")
            .addAggregation(
                    histogram("histo")
                            .field(FIELD_1_NAME)
                            .interval(interval)
                            .subAggregation(sum("field2Sum").field(FIELD_2_NAME))
                            .subAggregation(sum("field3Sum").field(FIELD_3_NAME))
                            .subAggregation(bucketSelector("bucketSelector", script, "field2Sum", "field3Sum")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    assertThat(deriv.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:BucketSelectorIT.java

示例10: testParseWithCarriageReturn

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testParseWithCarriageReturn() throws Exception {
    final String content = "{\"index\":[\"test0\", \"test1\"], \"request_cache\": true}\r\n" +
        "{\"inline\": {\"query\" : {\"match_{{template}}\" :{}}}, \"params\": {\"template\": \"all\" } }\r\n";
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry())
        .withContent(new BytesArray(content), XContentType.JSON).build();

    MultiSearchTemplateRequest request = RestMultiSearchTemplateAction.parseRequest(restRequest, true);

    assertThat(request.requests().size(), equalTo(1));
    assertThat(request.requests().get(0).getRequest().indices()[0], equalTo("test0"));
    assertThat(request.requests().get(0).getRequest().indices()[1], equalTo("test1"));
    assertThat(request.requests().get(0).getRequest().indices(), arrayContaining("test0", "test1"));
    assertThat(request.requests().get(0).getRequest().requestCache(), equalTo(true));
    assertThat(request.requests().get(0).getRequest().preference(), nullValue());
    assertNotNull(request.requests().get(0).getScript());
    assertEquals(ScriptType.INLINE, request.requests().get(0).getScriptType());
    assertEquals("{\"query\":{\"match_{{template}}\":{}}}", request.requests().get(0).getScript());
    assertEquals(1, request.requests().get(0).getScriptParams().size());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MultiSearchTemplateRequestTests.java

示例11: testParseInlineTemplateWithParams

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testParseInlineTemplateWithParams() throws Exception {
    String source = "{" +
            "    'inline' : {" +
            "      'query': { 'match' : { '{{my_field}}' : '{{my_value}}' } }," +
            "      'size' : '{{my_size}}'" +
            "    }," +
            "    'params' : {" +
            "        'my_field' : 'foo'," +
            "        'my_value' : 'bar'," +
            "        'my_size' : 5" +
            "    }" +
            "}";

    SearchTemplateRequest request = RestSearchTemplateAction.parse(newParser(source));
    assertThat(request.getScript(), equalTo("{\"query\":{\"match\":{\"{{my_field}}\":\"{{my_value}}\"}},\"size\":\"{{my_size}}\"}"));
    assertThat(request.getScriptType(), equalTo(ScriptType.INLINE));
    assertThat(request.getScriptParams().size(), equalTo(3));
    assertThat(request.getScriptParams(), hasEntry("my_field", "foo"));
    assertThat(request.getScriptParams(), hasEntry("my_value", "bar"));
    assertThat(request.getScriptParams(), hasEntry("my_size", 5));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SearchTemplateRequestTests.java

示例12: exec

import org.elasticsearch.script.ScriptType; //导入依赖的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

示例13: testCancellationDuringFetchPhase

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testCancellationDuringFetchPhase() throws Exception {

        List<ScriptedBlockPlugin> plugins = initBlockFactory();
        indexTestData();

        logger.info("Executing search");
        ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test")
            .addScriptField("test_field",
                new Script(ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())
            ).execute();

        awaitForBlock(plugins);
        cancelSearch(SearchAction.NAME);
        disableBlocks(plugins);
        logger.info("Segments {}", XContentHelper.toString(client().admin().indices().prepareSegments("test").get(), FORMAT_PARAMS));
        ensureSearchWasCancelled(searchResponse);
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SearchCancellationIT.java

示例14: testUpdateRequestWithBothScriptAndDoc

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testUpdateRequestWithBothScriptAndDoc() throws Exception {
    createTestIndex();
    ensureGreen();

    try {
        client().prepareUpdate(indexOrAlias(), "type1", "1")
                .setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
                .setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
                .execute().actionGet();
        fail("Should have thrown ActionRequestValidationException");
    } catch (ActionRequestValidationException e) {
        assertThat(e.validationErrors().size(), equalTo(1));
        assertThat(e.validationErrors().get(0), containsString("can't provide both script and doc"));
        assertThat(e.getMessage(), containsString("can't provide both script and doc"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:UpdateIT.java

示例15: testSingleValuedStringValueScript

import org.elasticsearch.script.ScriptType; //导入依赖的package包/类
public void testSingleValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field("str_value")
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CardinalityIT.java


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