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


Java ScriptType.INLINE属性代码示例

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


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

示例1: getElasticsearchCalendarFieldAggregation

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,代码行数:40,代码来源:ElasticsearchSearchQueryBase.java

示例2: testUnmapped

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,代码行数:21,代码来源:BucketSelectorIT.java

示例3: testInlineScriptSingleVariable

public void testInlineScriptSingleVariable() {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 > 100)", Collections.emptyMap());

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

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();

    for (int i = 0; i < buckets.size(); ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        Sum field2Sum = bucket.getAggregations().get("field2Sum");
        assertThat(field2Sum, notNullValue());
        double field2SumValue = field2Sum.getValue();
        assertThat(field2SumValue, greaterThan(100.0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:BucketSelectorIT.java

示例4: testInitMapReduceWithParams

public void testInitMapReduceWithParams() {
    Map<String, Object> varsMap = new HashMap<>();
    varsMap.put("multiplier", 1);

    Map<String, Object> params = new HashMap<>();
    params.put("_agg", new ArrayList<>());
    params.put("vars", varsMap);

    Script initScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "vars.multiplier = 3", Collections.emptyMap());
    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(vars.multiplier)", Collections.emptyMap());
    Script reduceScript =
        new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum aggs of agg values as a new aggregation", Collections.emptyMap());

    SearchResponse response = client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                    scriptedMetric("scripted")
                            .params(params)
                            .initScript(initScript)
                            .mapScript(mapScript)
                            .reduceScript(reduceScript))
            .get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits(), equalTo(numDocs));

    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(1));
    Object object = aggregationList.get(0);
    assertThat(object, notNullValue());
    assertThat(object, instanceOf(Number.class));
    assertThat(((Number) object).longValue(), equalTo(numDocs * 3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:ScriptedMetricIT.java

示例5: testParseTemplateAsSingleStringWithConditionalClause

public void testParseTemplateAsSingleStringWithConditionalClause() throws IOException {
    String templateString =
              "{"
            + "  \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + "  \"params\":{"
            + "    \"template\":\"all\","
            + "    \"use_it\": true"
            + "  }"
            + "}";
    XContentParser parser = createParser(JsonXContent.jsonXContent, templateString);
    Script script = Script.parse(parser);
    CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache",
            qe.compile(null, script.getIdOrCode(), Collections.emptyMap()));
    ExecutableScript executableScript = qe.executable(compiledScript, script.getParams());
    assertThat(((BytesReference) executableScript.run()).utf8ToString(), equalTo("{ \"match_all\":{} }"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:MustacheScriptEngineTests.java

示例6: testRawEscapedTemplate

public void testRawEscapedTemplate() throws IOException {
    String expectedTemplateString = "{\"match_{{template}}\": {}}\"";
    String query = "{\"template\": {\"inline\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}";
    Map<String, Object> params = new HashMap<>();
    params.put("template", "all");
    QueryBuilder expectedBuilder = new TemplateQueryBuilder(expectedTemplateString, ScriptType.INLINE, params);
    assertParsedQuery(query, expectedBuilder);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:TemplateQueryBuilderTests.java

示例7: testRawTemplate

public void testRawTemplate() throws IOException {
    String expectedTemplateString = "{\"match_{{template}}\":{}}";
    String query = "{\"template\": {\"inline\": {\"match_{{template}}\": {}},\"params\" : {\"template\" : \"all\"}}}";
    Map<String, Object> params = new HashMap<>();
    params.put("template", "all");
    QueryBuilder expectedBuilder = new TemplateQueryBuilder(expectedTemplateString, ScriptType.INLINE, params, XContentType.JSON);
    assertParsedQuery(query, expectedBuilder);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:TemplateQueryBuilderTests.java

示例8: testInlineScriptNamedVars

public void testInlineScriptNamedVars() {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(my_value1) ? false : (my_value1 + my_value2 > 100)", Collections.emptyMap());

    Map<String, String> bucketPathsMap = new HashMap<>();
    bucketPathsMap.put("my_value1", "field2Sum");
    bucketPathsMap.put("my_value2", "field3Sum");

    SearchResponse response = client().prepareSearch("idx")
            .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", bucketPathsMap, script)))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();

    for (int i = 0; i < buckets.size(); ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        Sum field2Sum = bucket.getAggregations().get("field2Sum");
        assertThat(field2Sum, notNullValue());
        double field2SumValue = field2Sum.getValue();
        Sum field3Sum = bucket.getAggregations().get("field3Sum");
        assertThat(field3Sum, notNullValue());
        double field3SumValue = field3Sum.getValue();
        assertThat(field2SumValue + field3SumValue, greaterThan(100.0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:BucketSelectorIT.java

示例9: testMinScoreFunctionScoreBasic

public void testMinScoreFunctionScoreBasic() throws IOException {
    index(INDEX, TYPE, jsonBuilder().startObject().field("num", 2).endObject());
    refresh();
    float score = randomFloat();
    float minScore = randomFloat();

    index(INDEX, TYPE, jsonBuilder().startObject()
            .field("num", 2)
            .field("random_score", score) // Pass the random score as a document field so that it can be extracted in the script
            .endObject());
    refresh();
    ensureYellow();

    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['random_score']", Collections.emptyMap());
    SearchResponse searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(scriptFunction(script)).setMinScore(minScore)))
    ).actionGet();
    if (score < minScore) {
        assertThat(searchResponse.getHits().getTotalHits(), is(0L));
    } else {
        assertThat(searchResponse.getHits().getTotalHits(), is(1L));
    }

    searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(new MatchAllQueryBuilder(), new FilterFunctionBuilder[] {
                            new FilterFunctionBuilder(scriptFunction(script)),
                            new FilterFunctionBuilder(scriptFunction(script))
                    }).scoreMode(FiltersFunctionScoreQuery.ScoreMode.AVG).setMinScore(minScore)))
            ).actionGet();
    if (score < minScore) {
        assertThat(searchResponse.getHits().getTotalHits(), is(0L));
    } else {
        assertThat(searchResponse.getHits().getTotalHits(), is(1L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:FunctionScoreIT.java

示例10: testPartiallyUnmapped

public void testPartiallyUnmapped() throws Exception {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", Collections.emptyMap());

    SearchResponse response = client().prepareSearch("idx", "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 histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();

    for (int i = 0; i < buckets.size(); ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        Sum field2Sum = bucket.getAggregations().get("field2Sum");
        assertThat(field2Sum, notNullValue());
        double field2SumValue = field2Sum.getValue();
        Sum field3Sum = bucket.getAggregations().get("field3Sum");
        assertThat(field3Sum, notNullValue());
        double field3SumValue = field3Sum.getValue();
        assertThat(field2SumValue + field3SumValue, greaterThan(100.0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:BucketSelectorIT.java

示例11: compile

@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,代码行数:27,代码来源:InternalTemplateService.java

示例12: testSingleValuedNumericScript

public void testSingleValuedNumericScript() throws Exception {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc[' + singleNumericField() + '].value", emptyMap());
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(script))
            .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,代码行数:13,代码来源:CardinalityIT.java

示例13: testMapReduceWithParams

public void testMapReduceWithParams() {
    Map<String, Object> varsMap = new HashMap<>();
    varsMap.put("multiplier", 1);
    Map<String, Object> params = new HashMap<>();
    params.put("_agg", new ArrayList<>());
    params.put("vars", varsMap);

    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(vars.multiplier)", Collections.emptyMap());
    Script reduceScript =
        new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum aggs of agg values as a new aggregation", Collections.emptyMap());

    SearchResponse response = client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                    scriptedMetric("scripted")
                            .params(params)
                            .mapScript(mapScript)
                            .reduceScript(reduceScript))
            .get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits(), equalTo(numDocs));

    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(1));
    Object object = aggregationList.get(0);
    assertThat(object, notNullValue());
    assertThat(object, instanceOf(Number.class));
    assertThat(((Number) object).longValue(), equalTo(numDocs));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ScriptedMetricIT.java

示例14: testMapWithParams

public void testMapWithParams() {
    Map<String, Object> params = new HashMap<>();
    params.put("_agg", new ArrayList<>());

    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", params);

    SearchResponse response = client().prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(scriptedMetric("scripted").params(params).mapScript(mapScript))
            .get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits(), equalTo(numDocs));

    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(getNumShards("idx").numPrimaries));
    long totalCount = 0;
    for (Object object : aggregationList) {
        assertThat(object, notNullValue());
        assertThat(object, instanceOf(List.class));
        List<?> list = (List<?>) object;
        for (Object o : list) {
            assertThat(o, notNullValue());
            assertThat(o, instanceOf(Number.class));
            Number numberValue = (Number) o;
            assertThat(numberValue, equalTo((Number) 1));
            totalCount += numberValue.longValue();
        }
    }
    assertThat(totalCount, equalTo(numDocs));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ScriptedMetricIT.java

示例15: testInlineScript2

public void testInlineScript2() {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 < _value1)", Collections.emptyMap());

    SearchResponse response = client()
            .prepareSearch("idx")
            .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 histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();

    for (int i = 0; i < buckets.size(); ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        Sum field2Sum = bucket.getAggregations().get("field2Sum");
        assertThat(field2Sum, notNullValue());
        double field2SumValue = field2Sum.getValue();
        Sum field3Sum = bucket.getAggregations().get("field3Sum");
        assertThat(field3Sum, notNullValue());
        double field3SumValue = field3Sum.getValue();
        assertThat(field3SumValue - field2SumValue, greaterThan(0.0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:BucketSelectorIT.java


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