use of org.elasticsearch.script.ScriptType in project elasticsearch by elastic.
the class UpdateRequest method updateOrCreateScript.
private void updateOrCreateScript(String scriptContent, ScriptType type, String lang, Map<String, Object> params) {
Script script = script();
if (script == null) {
script = new Script(type == null ? ScriptType.INLINE : type, lang, scriptContent == null ? "" : scriptContent, params);
} else {
String newScriptContent = scriptContent == null ? script.getIdOrCode() : scriptContent;
ScriptType newScriptType = type == null ? script.getType() : type;
String newScriptLang = lang == null ? script.getLang() : lang;
Map<String, Object> newScriptParams = params == null ? script.getParams() : params;
script = new Script(newScriptType, newScriptLang, newScriptContent, newScriptParams);
}
script(script);
}
use of org.elasticsearch.script.ScriptType in project elasticsearch by elastic.
the class BucketSelectorTests method createTestAggregatorFactory.
@Override
protected BucketSelectorPipelineAggregationBuilder createTestAggregatorFactory() {
String name = randomAsciiOfLengthBetween(3, 20);
Map<String, String> bucketsPaths = new HashMap<>();
int numBucketPaths = randomIntBetween(1, 10);
for (int i = 0; i < numBucketPaths; i++) {
bucketsPaths.put(randomAsciiOfLengthBetween(1, 20), randomAsciiOfLengthBetween(1, 40));
}
Script script;
if (randomBoolean()) {
script = new Script("script");
} else {
Map<String, Object> params = new HashMap<>();
if (randomBoolean()) {
params.put("foo", "bar");
}
ScriptType type = randomFrom(ScriptType.values());
script = new Script(type, type == ScriptType.STORED ? null : randomFrom("my_lang", Script.DEFAULT_SCRIPT_LANG), "script", params);
}
BucketSelectorPipelineAggregationBuilder factory = new BucketSelectorPipelineAggregationBuilder(name, bucketsPaths, script);
if (randomBoolean()) {
factory.gapPolicy(randomFrom(GapPolicy.values()));
}
return factory;
}
use of org.elasticsearch.script.ScriptType in project elasticsearch by elastic.
the class BucketScriptTests method createTestAggregatorFactory.
@Override
protected BucketScriptPipelineAggregationBuilder createTestAggregatorFactory() {
String name = randomAsciiOfLengthBetween(3, 20);
Map<String, String> bucketsPaths = new HashMap<>();
int numBucketPaths = randomIntBetween(1, 10);
for (int i = 0; i < numBucketPaths; i++) {
bucketsPaths.put(randomAsciiOfLengthBetween(1, 20), randomAsciiOfLengthBetween(1, 40));
}
Script script;
if (randomBoolean()) {
script = new Script("script");
} else {
Map<String, Object> params = new HashMap<>();
if (randomBoolean()) {
params.put("foo", "bar");
}
ScriptType type = randomFrom(ScriptType.values());
script = new Script(type, type == ScriptType.STORED ? null : randomFrom("my_lang", Script.DEFAULT_SCRIPT_LANG), "script", params);
}
BucketScriptPipelineAggregationBuilder factory = new BucketScriptPipelineAggregationBuilder(name, bucketsPaths, script);
if (randomBoolean()) {
factory.format(randomAsciiOfLengthBetween(1, 10));
}
if (randomBoolean()) {
factory.gapPolicy(randomFrom(GapPolicy.values()));
}
return factory;
}
use of org.elasticsearch.script.ScriptType in project elasticsearch by elastic.
the class InnerHitBuilderTests method randomScript.
static SearchSourceBuilder.ScriptField randomScript() {
ScriptType randomScriptType = randomFrom(ScriptType.values());
Map<String, Object> randomMap = new HashMap<>();
if (randomBoolean()) {
int numEntries = randomIntBetween(0, 32);
for (int i = 0; i < numEntries; i++) {
randomMap.put(String.valueOf(i), randomAsciiOfLength(16));
}
}
Script script = new Script(randomScriptType, randomScriptType == ScriptType.STORED ? null : randomAsciiOfLengthBetween(1, 4), randomAsciiOfLength(128), randomMap);
return new SearchSourceBuilder.ScriptField(randomAsciiOfLengthBetween(1, 32), script, randomBoolean());
}
use of org.elasticsearch.script.ScriptType in project elasticsearch by elastic.
the class RoundTripTests method randomScript.
private Script randomScript() {
ScriptType type = randomFrom(ScriptType.values());
String lang = random().nextBoolean() ? Script.DEFAULT_SCRIPT_LANG : randomSimpleString(random());
String idOrCode = randomSimpleString(random());
Map<String, Object> params = Collections.emptyMap();
return new Script(type, lang, idOrCode, params);
}
Aggregations