use of org.elasticsearch.script.Script in project elasticsearch by elastic.
the class MaxIT method testScriptMultiValuedWithParams.
@Override
public void testScriptMultiValuedWithParams() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("inc", 1);
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "[ doc['value'].value, doc['value'].value + inc ]", params);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(max("max").script(script)).get();
assertHitCount(searchResponse, 10);
Max max = searchResponse.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getName(), equalTo("max"));
assertThat(max.getValue(), equalTo(11.0));
}
use of org.elasticsearch.script.Script in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testScriptMultiValued.
@Override
public void testScriptMultiValued() throws Exception {
int sigDigits = randomSignificantDigits();
final double[] pcts = randomPercents(minValues, maxValues);
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).script(script).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValues, maxValues, sigDigits);
}
use of org.elasticsearch.script.Script in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testScriptSingleValuedWithParams.
@Override
public void testScriptSingleValuedWithParams() throws Exception {
int sigDigits = randomSignificantDigits();
Map<String, Object> params = new HashMap<>();
params.put("dec", 1);
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
final double[] pcts = randomPercents(minValue - 1, maxValue - 1);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).script(script).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValue - 1, maxValue - 1, sigDigits);
}
use of org.elasticsearch.script.Script in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testScriptMultiValuedWithParams.
@Override
public void testScriptMultiValuedWithParams() throws Exception {
int sigDigits = randomSignificantDigits();
Script script = AggregationTestScriptsPlugin.DECREMENT_ALL_VALUES;
final double[] pcts = randomPercents(minValues - 1, maxValues - 1);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).script(script).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValues - 1, maxValues - 1, sigDigits);
}
use of org.elasticsearch.script.Script in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testDontCacheScripts.
/**
* Make sure that a request using a script does not get cached and a request
* not using a script does get cached.
*/
public void testDontCacheScripts() throws Exception {
assertAcked(prepareCreate("cache_test_idx").addMapping("type", "d", "type=long").setSettings(Settings.builder().put("requests.cache.enable", true).put("number_of_shards", 1).put("number_of_replicas", 1)).get());
indexRandom(true, client().prepareIndex("cache_test_idx", "type", "1").setSource("s", 1), client().prepareIndex("cache_test_idx", "type", "2").setSource("s", 2));
// Make sure we are starting with a clear cache
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getHitCount(), equalTo(0L));
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getMissCount(), equalTo(0L));
// Test that a request using a script does not get cached
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(percentileRanks("foo").method(PercentilesMethod.HDR).field("d").values(50.0).script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))).get();
assertSearchResponse(r);
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getHitCount(), equalTo(0L));
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getMissCount(), equalTo(0L));
// To make sure that the cache is working test that a request not using
// a script is cached
r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(percentileRanks("foo").method(PercentilesMethod.HDR).field("d").values(50.0)).get();
assertSearchResponse(r);
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getHitCount(), equalTo(0L));
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache().getMissCount(), equalTo(1L));
}
Aggregations