mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 01:19:02 +00:00
parent
2e531902ff
commit
aeb97ff412
@ -170,7 +170,7 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
||||
sizeInBytes += request.upsertRequest().source().length();
|
||||
}
|
||||
if (request.script() != null) {
|
||||
sizeInBytes += request.script().getScript().length() * 2;
|
||||
sizeInBytes += request.script().getIdOrCode().length() * 2;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class UpdateHelper extends AbstractComponent {
|
||||
if (!"create".equals(scriptOpChoice)) {
|
||||
if (!"none".equals(scriptOpChoice)) {
|
||||
logger.warn("Used upsert operation [{}] for script [{}], doing nothing...", scriptOpChoice,
|
||||
request.script.getScript());
|
||||
request.script.getIdOrCode());
|
||||
}
|
||||
UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(),
|
||||
getResult.getVersion(), DocWriteResponse.Result.NOOP);
|
||||
@ -242,7 +242,7 @@ public class UpdateHelper extends AbstractComponent {
|
||||
update.setGetResult(extractGetResult(request, request.index(), getResult.getVersion(), updatedSourceAsMap, updateSourceContentType, getResult.internalSourceRef()));
|
||||
return new Result(update, DocWriteResponse.Result.NOOP, updatedSourceAsMap, updateSourceContentType);
|
||||
} else {
|
||||
logger.warn("Used update operation [{}] for script [{}], doing nothing...", operation, request.script.getScript());
|
||||
logger.warn("Used update operation [{}] for script [{}], doing nothing...", operation, request.script.getIdOrCode());
|
||||
UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), DocWriteResponse.Result.NOOP);
|
||||
return new Result(update, DocWriteResponse.Result.NOOP, updatedSourceAsMap, updateSourceContentType);
|
||||
}
|
||||
@ -251,7 +251,7 @@ public class UpdateHelper extends AbstractComponent {
|
||||
private Map<String, Object> executeScript(Script script, Map<String, Object> ctx) {
|
||||
try {
|
||||
if (scriptService != null) {
|
||||
ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.UPDATE, Collections.emptyMap());
|
||||
ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.UPDATE);
|
||||
executableScript.setNextVar("ctx", ctx);
|
||||
executableScript.run();
|
||||
// we need to unwrap the ctx...
|
||||
|
@ -224,7 +224,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||
*/
|
||||
@Deprecated
|
||||
public String scriptString() {
|
||||
return this.script == null ? null : this.script.getScript();
|
||||
return this.script == null ? null : this.script.getIdOrCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,13 +327,13 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||
private void updateOrCreateScript(String scriptContent, ScriptType type, String lang, Map<String, Object> params) {
|
||||
Script script = script();
|
||||
if (script == null) {
|
||||
script = new Script(scriptContent == null ? "" : scriptContent, type == null ? ScriptType.INLINE : type, lang, params);
|
||||
script = new Script(type == null ? ScriptType.INLINE : type, lang, scriptContent == null ? "" : scriptContent, params);
|
||||
} else {
|
||||
String newScriptContent = scriptContent == null ? script.getScript() : scriptContent;
|
||||
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(newScriptContent, newScriptType, newScriptLang, newScriptParams);
|
||||
script = new Script(newScriptType, newScriptLang, newScriptContent, newScriptParams);
|
||||
}
|
||||
script(script);
|
||||
}
|
||||
@ -347,7 +347,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||
*/
|
||||
@Deprecated
|
||||
public UpdateRequest script(String script, ScriptType scriptType, @Nullable Map<String, Object> scriptParams) {
|
||||
this.script = new Script(script, scriptType, null, scriptParams);
|
||||
this.script = new Script(scriptType, Script.DEFAULT_SCRIPT_LANG, script, scriptParams);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||
@Deprecated
|
||||
public UpdateRequest script(String script, @Nullable String scriptLang, ScriptType scriptType,
|
||||
@Nullable Map<String, Object> scriptParams) {
|
||||
this.script = new Script(script, scriptType, scriptLang, scriptParams);
|
||||
this.script = new Script(scriptType, scriptLang, script, scriptParams);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ public final class ConstructingObjectParser<Value, Context extends ParseFieldMat
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish parsing the object.
|
||||
* Finish parsing the object.
|
||||
*/
|
||||
private Value finish() {
|
||||
if (targetObject != null) {
|
||||
|
@ -131,6 +131,10 @@ public interface XContentParser extends Releasable {
|
||||
|
||||
Map<String, Object> mapOrdered() throws IOException;
|
||||
|
||||
Map<String, String> mapStrings() throws IOException;
|
||||
|
||||
Map<String, String> mapStringsOrdered() throws IOException;
|
||||
|
||||
List<Object> list() throws IOException;
|
||||
|
||||
List<Object> listOrderedMap() throws IOException;
|
||||
|
@ -21,6 +21,7 @@ package org.elasticsearch.common.xcontent;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.cbor.CborXContent;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.smile.SmileXContent;
|
||||
@ -32,7 +33,7 @@ import java.util.Locale;
|
||||
/**
|
||||
* The content type of {@link org.elasticsearch.common.xcontent.XContent}.
|
||||
*/
|
||||
public enum XContentType {
|
||||
public enum XContentType implements Writeable {
|
||||
|
||||
/**
|
||||
* A JSON based content type.
|
||||
@ -168,7 +169,8 @@ public enum XContentType {
|
||||
throw new IllegalStateException("Unknown XContentType with index [" + index + "]");
|
||||
}
|
||||
|
||||
public static void writeTo(XContentType contentType, StreamOutput out) throws IOException {
|
||||
out.writeVInt(contentType.index);
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(index);
|
||||
}
|
||||
}
|
||||
|
@ -215,6 +215,16 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||
return readOrderedMap(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> mapStrings() throws IOException {
|
||||
return readMapStrings(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> mapStringsOrdered() throws IOException {
|
||||
return readOrderedMapStrings(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> list() throws IOException {
|
||||
return readList(this);
|
||||
@ -229,10 +239,18 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||
Map<String, Object> newMap();
|
||||
}
|
||||
|
||||
interface MapStringsFactory {
|
||||
Map<String, String> newMap();
|
||||
}
|
||||
|
||||
static final MapFactory SIMPLE_MAP_FACTORY = HashMap::new;
|
||||
|
||||
static final MapFactory ORDERED_MAP_FACTORY = LinkedHashMap::new;
|
||||
|
||||
static final MapStringsFactory SIMPLE_MAP_STRINGS_FACTORY = HashMap::new;
|
||||
|
||||
static final MapStringsFactory ORDERED_MAP_STRINGS_FACTORY = LinkedHashMap::new;
|
||||
|
||||
static Map<String, Object> readMap(XContentParser parser) throws IOException {
|
||||
return readMap(parser, SIMPLE_MAP_FACTORY);
|
||||
}
|
||||
@ -241,6 +259,14 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||
return readMap(parser, ORDERED_MAP_FACTORY);
|
||||
}
|
||||
|
||||
static Map<String, String> readMapStrings(XContentParser parser) throws IOException {
|
||||
return readMapStrings(parser, SIMPLE_MAP_STRINGS_FACTORY);
|
||||
}
|
||||
|
||||
static Map<String, String> readOrderedMapStrings(XContentParser parser) throws IOException {
|
||||
return readMapStrings(parser, ORDERED_MAP_STRINGS_FACTORY);
|
||||
}
|
||||
|
||||
static List<Object> readList(XContentParser parser) throws IOException {
|
||||
return readList(parser, SIMPLE_MAP_FACTORY);
|
||||
}
|
||||
@ -269,6 +295,26 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||
return map;
|
||||
}
|
||||
|
||||
static Map<String, String> readMapStrings(XContentParser parser, MapStringsFactory mapStringsFactory) throws IOException {
|
||||
Map<String, String> map = mapStringsFactory.newMap();
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == null) {
|
||||
token = parser.nextToken();
|
||||
}
|
||||
if (token == XContentParser.Token.START_OBJECT) {
|
||||
token = parser.nextToken();
|
||||
}
|
||||
for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) {
|
||||
// Must point to field name
|
||||
String fieldName = parser.currentName();
|
||||
// And then the value...
|
||||
parser.nextToken();
|
||||
String value = parser.text();
|
||||
map.put(fieldName, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
static List<Object> readList(XContentParser parser, MapFactory mapFactory) throws IOException {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == null) {
|
||||
|
@ -576,7 +576,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
||||
if (scriptFields != null) {
|
||||
for (ScriptField field : scriptFields) {
|
||||
SearchScript searchScript = innerHitsContext.getQueryShardContext().getSearchScript(field.script(),
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
ScriptContext.Standard.SEARCH);
|
||||
innerHitsContext.scriptFields().add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
|
||||
field.fieldName(), searchScript, field.ignoreFailure()));
|
||||
}
|
||||
|
@ -127,8 +127,7 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
|
||||
}
|
||||
|
||||
public BytesReference getTemplateBytes(Script template) {
|
||||
ExecutableScript executable = scriptService.executable(template,
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
ExecutableScript executable = scriptService.executable(template, ScriptContext.Standard.SEARCH);
|
||||
return (BytesReference) executable.run();
|
||||
}
|
||||
|
||||
|
@ -338,18 +338,17 @@ public class QueryShardContext extends QueryRewriteContext {
|
||||
* Compiles (or retrieves from cache) and binds the parameters to the
|
||||
* provided script
|
||||
*/
|
||||
public final SearchScript getSearchScript(Script script, ScriptContext context, Map<String, String> params) {
|
||||
public final SearchScript getSearchScript(Script script, ScriptContext context) {
|
||||
failIfFrozen();
|
||||
return scriptService.search(lookup(), script, context, params);
|
||||
return scriptService.search(lookup(), script, context);
|
||||
}
|
||||
/**
|
||||
* Returns a lazily created {@link SearchScript} that is compiled immediately but can be pulled later once all
|
||||
* parameters are available.
|
||||
*/
|
||||
public final Function<Map<String, Object>, SearchScript> getLazySearchScript(Script script, ScriptContext context,
|
||||
Map<String, String> params) {
|
||||
public final Function<Map<String, Object>, SearchScript> getLazySearchScript(Script script, ScriptContext context) {
|
||||
failIfFrozen();
|
||||
CompiledScript compile = scriptService.compile(script, context, params);
|
||||
CompiledScript compile = scriptService.compile(script, context, script.getOptions());
|
||||
return (p) -> scriptService.search(lookup(), compile, p);
|
||||
}
|
||||
|
||||
@ -357,19 +356,18 @@ public class QueryShardContext extends QueryRewriteContext {
|
||||
* Compiles (or retrieves from cache) and binds the parameters to the
|
||||
* provided script
|
||||
*/
|
||||
public final ExecutableScript getExecutableScript(Script script, ScriptContext context, Map<String, String> params) {
|
||||
public final ExecutableScript getExecutableScript(Script script, ScriptContext context) {
|
||||
failIfFrozen();
|
||||
return scriptService.executable(script, context, params);
|
||||
return scriptService.executable(script, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lazily created {@link ExecutableScript} that is compiled immediately but can be pulled later once all
|
||||
* parameters are available.
|
||||
*/
|
||||
public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(Script script, ScriptContext context,
|
||||
Map<String, String> params) {
|
||||
public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(Script script, ScriptContext context) {
|
||||
failIfFrozen();
|
||||
CompiledScript executable = scriptService.compile(script, context, params);
|
||||
CompiledScript executable = scriptService.compile(script, context, script.getOptions());
|
||||
return (p) -> scriptService.executable(executable, p);
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.LeafSearchScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -83,7 +79,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
||||
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName(), script);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
@ -104,7 +100,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||
} else if (parseContext.isDeprecatedSetting(currentFieldName)) {
|
||||
// skip
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
|
||||
@ -114,7 +110,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||
queryName = parser.text();
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
|
||||
@ -133,7 +129,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
return new ScriptQuery(script, context.getSearchScript(script, ScriptContext.Standard.SEARCH, Collections.emptyMap()));
|
||||
return new ScriptQuery(script, context.getSearchScript(script, ScriptContext.Standard.SEARCH));
|
||||
}
|
||||
|
||||
static class ScriptQuery extends Query {
|
||||
|
@ -30,12 +30,10 @@ import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.index.query.QueryShardException;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -74,7 +72,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder<ScriptScore
|
||||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(getName());
|
||||
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
||||
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName(), script);
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
@ -96,7 +94,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder<ScriptScore
|
||||
@Override
|
||||
protected ScoreFunction doToFunction(QueryShardContext context) {
|
||||
try {
|
||||
SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
|
||||
return new ScriptScoreFunction(script, searchScript);
|
||||
} catch (Exception e) {
|
||||
throw new QueryShardException(context, "script_score: the script could not be loaded", e);
|
||||
@ -113,7 +111,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder<ScriptScore
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
|
||||
|
@ -43,7 +43,7 @@ public class InternalTemplateService implements TemplateService {
|
||||
int mustacheStart = template.indexOf("{{");
|
||||
int mustacheEnd = template.indexOf("}}");
|
||||
if (mustacheStart != -1 && mustacheEnd != -1 && mustacheStart < mustacheEnd) {
|
||||
Script script = new Script(template, ScriptType.INLINE, "mustache", Collections.emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, "mustache", template, Collections.emptyMap());
|
||||
CompiledScript compiledScript = scriptService.compile(
|
||||
script,
|
||||
ScriptContext.Standard.INGEST,
|
||||
|
@ -19,281 +19,600 @@
|
||||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Script holds all the parameters necessary to compile or find in cache and then execute a script.
|
||||
* Script represents used-defined input that can be used to
|
||||
* compile and execute a script from the {@link ScriptService}
|
||||
* based on the {@link ScriptType}.
|
||||
*/
|
||||
public final class Script implements ToXContent, Writeable {
|
||||
|
||||
/**
|
||||
* The name of the of the default scripting language.
|
||||
*/
|
||||
public static final String DEFAULT_SCRIPT_LANG = "painless";
|
||||
|
||||
private String script;
|
||||
private ScriptType type;
|
||||
@Nullable private String lang;
|
||||
@Nullable private Map<String, Object> params;
|
||||
@Nullable private XContentType contentType;
|
||||
/**
|
||||
* The name of the default template language.
|
||||
*/
|
||||
public static final String DEFAULT_TEMPLATE_LANG = "mustache";
|
||||
|
||||
/**
|
||||
* Constructor for simple inline script. The script will have no lang or params set.
|
||||
*
|
||||
* @param script The inline script to execute.
|
||||
* The default {@link ScriptType}.
|
||||
*/
|
||||
public Script(String script) {
|
||||
this(script, ScriptType.INLINE, null, null);
|
||||
}
|
||||
|
||||
public Script(String script, ScriptType type, String lang, @Nullable Map<String, ?> params) {
|
||||
this(script, type, lang, params, null);
|
||||
}
|
||||
public static final ScriptType DEFAULT_SCRIPT_TYPE = ScriptType.INLINE;
|
||||
|
||||
/**
|
||||
* Constructor for Script.
|
||||
*
|
||||
* @param script The cache key of the script to be compiled/executed. For inline scripts this is the actual
|
||||
* script source code. For indexed scripts this is the id used in the request. For on file
|
||||
* scripts this is the file name.
|
||||
* @param type The type of script -- dynamic, stored, or file.
|
||||
* @param lang The language of the script to be compiled/executed.
|
||||
* @param params The map of parameters the script will be executed with.
|
||||
* @param contentType The {@link XContentType} of the script. Only relevant for inline scripts that have not been
|
||||
* defined as a plain string, but as json or yaml content. This class needs this information
|
||||
* when serializing the script back to xcontent.
|
||||
* Compiler option for {@link XContentType} used for templates.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Script(String script, ScriptType type, String lang, @Nullable Map<String, ?> params,
|
||||
@Nullable XContentType contentType) {
|
||||
if (contentType != null && type != ScriptType.INLINE) {
|
||||
throw new IllegalArgumentException("The parameter contentType only makes sense for inline scripts");
|
||||
public static final String CONTENT_TYPE_OPTION = "content_type";
|
||||
|
||||
/**
|
||||
* Standard {@link ParseField} for outer level of script queries.
|
||||
*/
|
||||
public static final ParseField SCRIPT_PARSE_FIELD = new ParseField("script");
|
||||
|
||||
/**
|
||||
* Standard {@link ParseField} for lang on the inner level.
|
||||
*/
|
||||
public static final ParseField LANG_PARSE_FIELD = new ParseField("lang");
|
||||
|
||||
/**
|
||||
* Standard {@link ParseField} for options on the inner level.
|
||||
*/
|
||||
public static final ParseField OPTIONS_PARSE_FIELD = new ParseField("options");
|
||||
|
||||
/**
|
||||
* Standard {@link ParseField} for params on the inner level.
|
||||
*/
|
||||
public static final ParseField PARAMS_PARSE_FIELD = new ParseField("params");
|
||||
|
||||
/**
|
||||
* Unreleased version used for {@link Script} non-null members format of read/write.
|
||||
*/
|
||||
public static final Version V_5_1_0_UNRELEASED = Version.fromId(5010099);
|
||||
|
||||
/**
|
||||
* Helper class used by {@link ObjectParser} to store mutable {@link Script} variables and then
|
||||
* construct an immutable {@link Script} object based on parsed XContent.
|
||||
*/
|
||||
private static final class Builder {
|
||||
private ScriptType type;
|
||||
private String lang;
|
||||
private String idOrCode;
|
||||
private Map<String, String> options;
|
||||
private Map<String, Object> params;
|
||||
|
||||
private Builder() {
|
||||
// This cannot default to an empty map because options are potentially added at multiple points.
|
||||
this.options = new HashMap<>();
|
||||
this.params = Collections.emptyMap();
|
||||
}
|
||||
this.script = Objects.requireNonNull(script);
|
||||
|
||||
/**
|
||||
* Since inline scripts can accept code rather than just an id, they must also be able
|
||||
* to handle template parsing, hence the need for custom parsing code. Templates can
|
||||
* consist of either an {@link String} or a JSON object. If a JSON object is discovered
|
||||
* then the content type option must also be saved as a compiler option.
|
||||
*/
|
||||
private void setInline(XContentParser parser) {
|
||||
try {
|
||||
if (type != null) {
|
||||
throwOnlyOneOfType();
|
||||
}
|
||||
|
||||
type = ScriptType.INLINE;
|
||||
|
||||
if (parser.currentToken() == Token.START_OBJECT) {
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
|
||||
idOrCode = builder.copyCurrentStructure(parser).bytes().utf8ToString();
|
||||
options.put(CONTENT_TYPE_OPTION, parser.contentType().mediaType());
|
||||
} else {
|
||||
idOrCode = parser.text();
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both the id and the type of the stored script.
|
||||
*/
|
||||
private void setStored(String idOrCode) {
|
||||
if (type != null) {
|
||||
throwOnlyOneOfType();
|
||||
}
|
||||
|
||||
type = ScriptType.STORED;
|
||||
this.idOrCode = idOrCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both the id and the type of the file script.
|
||||
*/
|
||||
private void setFile(String idOrCode) {
|
||||
if (type != null) {
|
||||
throwOnlyOneOfType();
|
||||
}
|
||||
|
||||
type = ScriptType.FILE;
|
||||
this.idOrCode = idOrCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to throw an exception if more than one type of {@link Script} is specified.
|
||||
*/
|
||||
private void throwOnlyOneOfType() {
|
||||
throw new IllegalArgumentException("must only use one of [" +
|
||||
ScriptType.INLINE.getParseField().getPreferredName() + " + , " +
|
||||
ScriptType.STORED.getParseField().getPreferredName() + " + , " +
|
||||
ScriptType.FILE.getParseField().getPreferredName() + "]" +
|
||||
" when specifying a script");
|
||||
}
|
||||
|
||||
private void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options may have already been added if an inline template was specified.
|
||||
* Appends the user-defined compiler options with the internal compiler options.
|
||||
*/
|
||||
private void setOptions(Map<String, String> options) {
|
||||
this.options.putAll(options);
|
||||
}
|
||||
|
||||
private void setParams(Map<String, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the parameters and creates an {@link Script}.
|
||||
* @param defaultLang The default lang is not a compile-time constant and must be provided
|
||||
* at run-time this way in case a legacy default language is used from
|
||||
* previously stored queries.
|
||||
*/
|
||||
private Script build(String defaultLang) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"must specify either code for an [" + ScriptType.INLINE.getParseField().getPreferredName() + "] script " +
|
||||
"or an id for a [" + ScriptType.STORED.getParseField().getPreferredName() + "] script " +
|
||||
"or [" + ScriptType.FILE.getParseField().getPreferredName() + "] script");
|
||||
}
|
||||
|
||||
if (idOrCode == null) {
|
||||
throw new IllegalArgumentException("must specify an id or code for a script");
|
||||
}
|
||||
|
||||
if (options.size() > 1 || options.size() == 1 && options.get(CONTENT_TYPE_OPTION) == null) {
|
||||
throw new IllegalArgumentException("illegal compiler options [" + options + "] specified");
|
||||
}
|
||||
|
||||
return new Script(type, this.lang == null ? defaultLang : this.lang, idOrCode, options, params);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ObjectParser<Builder, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>("script", Builder::new);
|
||||
|
||||
static {
|
||||
// Defines the fields necessary to parse a Script as XContent using an ObjectParser.
|
||||
PARSER.declareField(Builder::setInline, parser -> parser, ScriptType.INLINE.getParseField(), ValueType.OBJECT_OR_STRING);
|
||||
PARSER.declareString(Builder::setStored, ScriptType.STORED.getParseField());
|
||||
PARSER.declareString(Builder::setFile, ScriptType.FILE.getParseField());
|
||||
PARSER.declareString(Builder::setLang, LANG_PARSE_FIELD);
|
||||
PARSER.declareField(Builder::setOptions, XContentParser::mapStrings, OPTIONS_PARSE_FIELD, ValueType.OBJECT);
|
||||
PARSER.declareField(Builder::setParams, XContentParser::map, PARAMS_PARSE_FIELD, ValueType.OBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)}
|
||||
* using the default scripting language.
|
||||
*/
|
||||
public static Script parse(XContentParser parser, ParseFieldMatcher matcher) throws IOException {
|
||||
return parse(parser, matcher, DEFAULT_SCRIPT_LANG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)} using the
|
||||
* {@link ParseFieldMatcher} and scripting language provided by the {@link QueryParseContext}.
|
||||
*/
|
||||
public static Script parse(XContentParser parser, QueryParseContext context) throws IOException {
|
||||
return parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This will parse XContent into a {@link Script}. The following formats can be parsed:
|
||||
*
|
||||
* The simple format defaults to an {@link ScriptType#INLINE} with no compiler options or user-defined params:
|
||||
*
|
||||
* Example:
|
||||
* {@code
|
||||
* "return Math.log(doc.popularity) * 100;"
|
||||
* }
|
||||
*
|
||||
* The complex format where {@link ScriptType} and idOrCode are required while lang, options and params are not required.
|
||||
*
|
||||
* {@code
|
||||
* {
|
||||
* "<type (inline, stored, file)>" : "<idOrCode>",
|
||||
* "lang" : "<lang>",
|
||||
* "options" : {
|
||||
* "option0" : "<option0>",
|
||||
* "option1" : "<option1>",
|
||||
* ...
|
||||
* },
|
||||
* "params" : {
|
||||
* "param0" : "<param0>",
|
||||
* "param1" : "<param1>",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Example:
|
||||
* {@code
|
||||
* {
|
||||
* "inline" : "return Math.log(doc.popularity) * params.multiplier",
|
||||
* "lang" : "painless",
|
||||
* "params" : {
|
||||
* "multiplier" : 100.0
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* This also handles templates in a special way. If a complexly formatted query is specified as another complex
|
||||
* JSON object the query is assumed to be a template, and the format will be preserved.
|
||||
*
|
||||
* {@code
|
||||
* {
|
||||
* "inline" : { "query" : ... },
|
||||
* "lang" : "<lang>",
|
||||
* "options" : {
|
||||
* "option0" : "<option0>",
|
||||
* "option1" : "<option1>",
|
||||
* ...
|
||||
* },
|
||||
* "params" : {
|
||||
* "param0" : "<param0>",
|
||||
* "param1" : "<param1>",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param parser The {@link XContentParser} to be used.
|
||||
* @param matcher The {@link ParseFieldMatcher} to be used.
|
||||
* @param defaultLang The default language to use if no language is specified. The default language isn't necessarily
|
||||
* the one defined by {@link Script#DEFAULT_SCRIPT_LANG} due to backwards compatiblity requirements
|
||||
* related to stored queries using previously default languauges.
|
||||
* @return The parsed {@link Script}.
|
||||
*/
|
||||
public static Script parse(XContentParser parser, ParseFieldMatcher matcher, String defaultLang) throws IOException {
|
||||
Objects.requireNonNull(defaultLang);
|
||||
|
||||
Token token = parser.currentToken();
|
||||
|
||||
if (token == null) {
|
||||
token = parser.nextToken();
|
||||
}
|
||||
|
||||
if (token == Token.VALUE_STRING) {
|
||||
return new Script(ScriptType.INLINE, defaultLang, parser.text(), Collections.emptyMap());
|
||||
}
|
||||
|
||||
return PARSER.apply(parser, () -> matcher).build(defaultLang);
|
||||
}
|
||||
|
||||
private final ScriptType type;
|
||||
private final String lang;
|
||||
private final String idOrCode;
|
||||
private final Map<String, String> options;
|
||||
private final Map<String, Object> params;
|
||||
|
||||
/**
|
||||
* Constructor for simple script using the default language and default type.
|
||||
* @param idOrCode The id or code to use dependent on the default script type.
|
||||
*/
|
||||
public Script(String idOrCode) {
|
||||
this(DEFAULT_SCRIPT_TYPE, DEFAULT_SCRIPT_LANG, idOrCode, Collections.emptyMap(), Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a script that does not need to use compiler options.
|
||||
* @param type The {@link ScriptType}.
|
||||
* @param lang The lang for this {@link Script}.
|
||||
* @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}.
|
||||
* The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}.
|
||||
* @param params The user-defined params to be bound for script execution.
|
||||
*/
|
||||
public Script(ScriptType type, String lang, String idOrCode, Map<String, Object> params) {
|
||||
this(type, lang, idOrCode, Collections.emptyMap(), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a script that requires the use of compiler options.
|
||||
* @param type The {@link ScriptType}.
|
||||
* @param lang The lang for this {@link Script}.
|
||||
* @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}.
|
||||
* The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}.
|
||||
* @param options The options to be passed to the compiler for use at compile-time.
|
||||
* @param params The user-defined params to be bound for script execution.
|
||||
*/
|
||||
public Script(ScriptType type, String lang, String idOrCode, Map<String, String> options, Map<String, Object> params) {
|
||||
this.idOrCode = Objects.requireNonNull(idOrCode);
|
||||
this.type = Objects.requireNonNull(type);
|
||||
this.lang = lang == null ? DEFAULT_SCRIPT_LANG : lang;
|
||||
this.params = (Map<String, Object>) params;
|
||||
this.contentType = contentType;
|
||||
this.lang = Objects.requireNonNull(lang);
|
||||
this.options = Collections.unmodifiableMap(Objects.requireNonNull(options));
|
||||
this.params = Collections.unmodifiableMap(Objects.requireNonNull(params));
|
||||
|
||||
if (type != ScriptType.INLINE && !options.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Compiler options [" + options + "] cannot be specified at runtime for [" + type + "] scripts.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Script} read from an input stream.
|
||||
*/
|
||||
public Script(StreamInput in) throws IOException {
|
||||
script = in.readString();
|
||||
if (in.readBoolean()) {
|
||||
type = ScriptType.readFrom(in);
|
||||
}
|
||||
lang = in.readOptionalString();
|
||||
params = in.readMap();
|
||||
if (in.readBoolean()) {
|
||||
contentType = XContentType.readFrom(in);
|
||||
// Version 5.1+ requires all Script members to be non-null and supports the potential
|
||||
// for more options than just XContentType. Reorders the read in contents to be in
|
||||
// same order as the constructor.
|
||||
if (in.getVersion().onOrAfter(V_5_1_0_UNRELEASED)) {
|
||||
this.type = ScriptType.readFrom(in);
|
||||
this.lang = in.readString();
|
||||
this.idOrCode = in.readString();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> options = (Map<String, String>)(Map)in.readMap();
|
||||
this.options = options;
|
||||
this.params = in.readMap();
|
||||
// Prior to version 5.1 the script members are read in certain cases as optional and given
|
||||
// default values when necessary. Also the only option supported is for XContentType.
|
||||
} else {
|
||||
String idOrCode = in.readString();
|
||||
ScriptType type;
|
||||
|
||||
if (in.readBoolean()) {
|
||||
type = ScriptType.readFrom(in);
|
||||
} else {
|
||||
type = DEFAULT_SCRIPT_TYPE;
|
||||
}
|
||||
|
||||
String lang = in.readOptionalString();
|
||||
|
||||
if (lang == null) {
|
||||
lang = DEFAULT_SCRIPT_LANG;
|
||||
}
|
||||
|
||||
Map<String, Object> params = in.readMap();
|
||||
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
}
|
||||
|
||||
Map<String, String> options = new HashMap<>();
|
||||
|
||||
if (in.readBoolean()) {
|
||||
XContentType contentType = XContentType.readFrom(in);
|
||||
options.put(CONTENT_TYPE_OPTION, contentType.mediaType());
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.lang = lang;
|
||||
this.idOrCode = idOrCode;
|
||||
this.options = options;
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(script);
|
||||
boolean hasType = type != null;
|
||||
out.writeBoolean(hasType);
|
||||
if (hasType) {
|
||||
// Version 5.1+ requires all Script members to be non-null and supports the potential
|
||||
// for more options than just XContentType. Reorders the written out contents to be in
|
||||
// same order as the constructor.
|
||||
if (out.getVersion().onOrAfter(V_5_1_0_UNRELEASED)) {
|
||||
type.writeTo(out);
|
||||
}
|
||||
out.writeOptionalString(lang);
|
||||
out.writeMap(params);
|
||||
boolean hasContentType = contentType != null;
|
||||
out.writeBoolean(hasContentType);
|
||||
if (hasContentType) {
|
||||
XContentType.writeTo(contentType, out);
|
||||
out.writeString(lang);
|
||||
out.writeString(idOrCode);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> options = (Map<String, Object>)(Map)this.options;
|
||||
out.writeMap(options);
|
||||
out.writeMap(params);
|
||||
// Prior to version 5.1 the Script members were possibly written as optional or null, though this is no longer
|
||||
// necessary since Script members cannot be null anymore, and there is no case where a null value wasn't equivalent
|
||||
// to it's default value when actually compiling/executing a script. Meaning, there are no backwards compatibility issues,
|
||||
// and now there's enforced consistency. Also the only supported compiler option was XContentType.
|
||||
} else {
|
||||
out.writeString(idOrCode);
|
||||
out.writeBoolean(true);
|
||||
type.writeTo(out);
|
||||
out.writeBoolean(true);
|
||||
out.writeString(lang);
|
||||
out.writeMap(params.isEmpty() ? null : params);
|
||||
|
||||
if (options.containsKey(CONTENT_TYPE_OPTION)) {
|
||||
XContentType contentType = XContentType.fromMediaTypeOrFormat(options.get(CONTENT_TYPE_OPTION));
|
||||
out.writeBoolean(true);
|
||||
contentType.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for getting the script.
|
||||
* @return The cache key of the script to be compiled/executed. For dynamic scripts this is the actual
|
||||
* script source code. For indexed scripts this is the id used in the request. For on disk scripts
|
||||
* this is the file name.
|
||||
*/
|
||||
public String getScript() {
|
||||
return script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for getting the type.
|
||||
* This will build scripts into the following XContent structure:
|
||||
*
|
||||
* @return The type of script -- inline, stored, or file.
|
||||
* {@code
|
||||
* {
|
||||
* "<type (inline, stored, file)>" : "<idOrCode>",
|
||||
* "lang" : "<lang>",
|
||||
* "options" : {
|
||||
* "option0" : "<option0>",
|
||||
* "option1" : "<option1>",
|
||||
* ...
|
||||
* },
|
||||
* "params" : {
|
||||
* "param0" : "<param0>",
|
||||
* "param1" : "<param1>",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Example:
|
||||
* {@code
|
||||
* {
|
||||
* "inline" : "return Math.log(doc.popularity) * params.multiplier;",
|
||||
* "lang" : "painless",
|
||||
* "params" : {
|
||||
* "multiplier" : 100.0
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Note that options and params will only be included if there have been any specified.
|
||||
*
|
||||
* This also handles templates in a special way. If the {@link Script#CONTENT_TYPE_OPTION} option
|
||||
* is provided and the {@link ScriptType#INLINE} is specified then the template will be preserved as a raw field.
|
||||
*
|
||||
* {@code
|
||||
* {
|
||||
* "inline" : { "query" : ... },
|
||||
* "lang" : "<lang>",
|
||||
* "options" : {
|
||||
* "option0" : "<option0>",
|
||||
* "option1" : "<option1>",
|
||||
* ...
|
||||
* },
|
||||
* "params" : {
|
||||
* "param0" : "<param0>",
|
||||
* "param1" : "<param1>",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||
builder.startObject();
|
||||
|
||||
String contentType = options.get(CONTENT_TYPE_OPTION);
|
||||
|
||||
if (type == ScriptType.INLINE && contentType != null && builder.contentType().mediaType().equals(contentType)) {
|
||||
builder.rawField(type.getParseField().getPreferredName(), new BytesArray(idOrCode));
|
||||
} else {
|
||||
builder.field(type.getParseField().getPreferredName(), idOrCode);
|
||||
}
|
||||
|
||||
builder.field(LANG_PARSE_FIELD.getPreferredName(), lang);
|
||||
|
||||
if (!options.isEmpty()) {
|
||||
builder.field(OPTIONS_PARSE_FIELD.getPreferredName(), options);
|
||||
}
|
||||
|
||||
if (!params.isEmpty()) {
|
||||
builder.field(PARAMS_PARSE_FIELD.getPreferredName(), params);
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}.
|
||||
* The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}.
|
||||
*/
|
||||
public String getIdOrCode() {
|
||||
return idOrCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link ScriptType} for this {@link Script}.
|
||||
*/
|
||||
public ScriptType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for getting language.
|
||||
*
|
||||
* @return The language of the script to be compiled/executed.
|
||||
* @return The language for this {@link Script}.
|
||||
*/
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for getting the parameters.
|
||||
*
|
||||
* @return The map of parameters the script will be executed with.
|
||||
* @return The map of compiler options for this {@link Script}.
|
||||
*/
|
||||
public Map<String, String> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The map of user-defined params for this {@link Script}.
|
||||
*/
|
||||
public Map<String, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The content type of the script if it is an inline script and the script has been defined as json
|
||||
* or yaml content instead of a plain string.
|
||||
*/
|
||||
public XContentType getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||
if (type == null) {
|
||||
return builder.value(script);
|
||||
}
|
||||
builder.startObject();
|
||||
if (type == ScriptType.INLINE && contentType != null && builder.contentType() == contentType) {
|
||||
builder.rawField(type.getParseField().getPreferredName(), new BytesArray(script));
|
||||
} else {
|
||||
builder.field(type.getParseField().getPreferredName(), script);
|
||||
}
|
||||
if (lang != null) {
|
||||
builder.field(ScriptField.LANG.getPreferredName(), lang);
|
||||
}
|
||||
if (params != null) {
|
||||
builder.field(ScriptField.PARAMS.getPreferredName(), params);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
public static Script parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
|
||||
return parse(parser, parseFieldMatcher, null);
|
||||
}
|
||||
Script script = (Script)o;
|
||||
|
||||
public static Script parse(XContentParser parser, QueryParseContext context) {
|
||||
try {
|
||||
return parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} catch (IOException e) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Error parsing [" + ScriptField.SCRIPT.getPreferredName() + "] field", e);
|
||||
}
|
||||
}
|
||||
if (type != script.type) return false;
|
||||
if (!lang.equals(script.lang)) return false;
|
||||
if (!idOrCode.equals(script.idOrCode)) return false;
|
||||
if (!options.equals(script.options)) return false;
|
||||
return params.equals(script.params);
|
||||
|
||||
public static Script parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher, @Nullable String lang) throws IOException {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
// If the parser hasn't yet been pushed to the first token, do it now
|
||||
if (token == null) {
|
||||
token = parser.nextToken();
|
||||
}
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
return new Script(parser.text(), ScriptType.INLINE, lang, null);
|
||||
}
|
||||
if (token != XContentParser.Token.START_OBJECT) {
|
||||
throw new ElasticsearchParseException("expected a string value or an object, but found [{}] instead", token);
|
||||
}
|
||||
String script = null;
|
||||
ScriptType type = null;
|
||||
Map<String, Object> params = null;
|
||||
XContentType contentType = null;
|
||||
String cfn = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
cfn = parser.currentName();
|
||||
} else if (parseFieldMatcher.match(cfn, ScriptType.INLINE.getParseField())) {
|
||||
type = ScriptType.INLINE;
|
||||
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
contentType = parser.contentType();
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
||||
script = builder.copyCurrentStructure(parser).bytes().utf8ToString();
|
||||
} else {
|
||||
script = parser.text();
|
||||
}
|
||||
} else if (parseFieldMatcher.match(cfn, ScriptType.FILE.getParseField())) {
|
||||
type = ScriptType.FILE;
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
script = parser.text();
|
||||
} else {
|
||||
throw new ElasticsearchParseException("expected a string value for field [{}], but found [{}]", cfn, token);
|
||||
}
|
||||
} else if (parseFieldMatcher.match(cfn, ScriptType.STORED.getParseField())) {
|
||||
type = ScriptType.STORED;
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
script = parser.text();
|
||||
} else {
|
||||
throw new ElasticsearchParseException("expected a string value for field [{}], but found [{}]", cfn, token);
|
||||
}
|
||||
} else if (parseFieldMatcher.match(cfn, ScriptField.LANG)) {
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
lang = parser.text();
|
||||
} else {
|
||||
throw new ElasticsearchParseException("expected a string value for field [{}], but found [{}]", cfn, token);
|
||||
}
|
||||
} else if (parseFieldMatcher.match(cfn, ScriptField.PARAMS)) {
|
||||
if (token == XContentParser.Token.START_OBJECT) {
|
||||
params = parser.map();
|
||||
} else {
|
||||
throw new ElasticsearchParseException("expected an object for field [{}], but found [{}]", cfn, token);
|
||||
}
|
||||
} else {
|
||||
throw new ElasticsearchParseException("unexpected field [{}]", cfn);
|
||||
}
|
||||
}
|
||||
if (script == null) {
|
||||
throw new ElasticsearchParseException("expected one of [{}], [{}] or [{}] fields, but found none",
|
||||
ScriptType.INLINE.getParseField() .getPreferredName(), ScriptType.FILE.getParseField().getPreferredName(),
|
||||
ScriptType.STORED.getParseField() .getPreferredName());
|
||||
}
|
||||
return new Script(script, type, lang, params, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(lang, params, script, type, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Script other = (Script) obj;
|
||||
|
||||
return Objects.equals(lang, other.lang) &&
|
||||
Objects.equals(params, other.params) &&
|
||||
Objects.equals(script, other.script) &&
|
||||
Objects.equals(type, other.type) &&
|
||||
Objects.equals(contentType, other.contentType);
|
||||
int result = type.hashCode();
|
||||
result = 31 * result + lang.hashCode();
|
||||
result = 31 * result + idOrCode.hashCode();
|
||||
result = 31 * result + options.hashCode();
|
||||
result = 31 * result + params.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[script: " + script + ", type: " + type.getParseField().getPreferredName() + ", lang: "
|
||||
+ lang + ", params: " + params + "]";
|
||||
return "Script{" +
|
||||
"type=" + type +
|
||||
", lang='" + lang + '\'' +
|
||||
", idOrCode='" + idOrCode + '\'' +
|
||||
", options=" + options +
|
||||
", params=" + params +
|
||||
'}';
|
||||
}
|
||||
|
||||
public interface ScriptField {
|
||||
ParseField SCRIPT = new ParseField("script");
|
||||
ParseField LANG = new ParseField("lang");
|
||||
ParseField PARAMS = new ParseField("params");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -274,9 +274,9 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
||||
|
||||
String lang = script.getLang();
|
||||
ScriptType type = script.getType();
|
||||
//script.getScript() could return either a name or code for a script,
|
||||
//script.getIdOrCode() could return either a name or code for a script,
|
||||
//but we check for a file script name first and an indexed script name second
|
||||
String name = script.getScript();
|
||||
String name = script.getIdOrCode();
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Compiling lang: [{}] type: [{}] script: {}", lang, type, name);
|
||||
@ -296,8 +296,8 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
||||
return compiledScript;
|
||||
}
|
||||
|
||||
//script.getScript() will be code if the script type is inline
|
||||
String code = script.getScript();
|
||||
//script.getIdOrCode() will be code if the script type is inline
|
||||
String code = script.getIdOrCode();
|
||||
|
||||
if (type == ScriptType.STORED) {
|
||||
//The look up for an indexed script must be done every time in case
|
||||
@ -468,22 +468,22 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
||||
/**
|
||||
* Compiles (or retrieves from cache) and executes the provided script
|
||||
*/
|
||||
public ExecutableScript executable(Script script, ScriptContext scriptContext, Map<String, String> params) {
|
||||
return executable(compile(script, scriptContext, params), script.getParams());
|
||||
public ExecutableScript executable(Script script, ScriptContext scriptContext) {
|
||||
return executable(compile(script, scriptContext, script.getOptions()), script.getParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a previously compiled script provided as an argument
|
||||
*/
|
||||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
return getScriptEngineServiceForLang(compiledScript.lang()).executable(compiledScript, vars);
|
||||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> params) {
|
||||
return getScriptEngineServiceForLang(compiledScript.lang()).executable(compiledScript, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles (or retrieves from cache) and executes the provided search script
|
||||
*/
|
||||
public SearchScript search(SearchLookup lookup, Script script, ScriptContext scriptContext, Map<String, String> params) {
|
||||
CompiledScript compiledScript = compile(script, scriptContext, params);
|
||||
public SearchScript search(SearchLookup lookup, Script script, ScriptContext scriptContext) {
|
||||
CompiledScript compiledScript = compile(script, scriptContext, script.getOptions());
|
||||
return search(lookup, compiledScript, script.getParams());
|
||||
}
|
||||
|
||||
|
@ -769,8 +769,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
||||
}
|
||||
if (source.scriptFields() != null) {
|
||||
for (org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField field : source.scriptFields()) {
|
||||
SearchScript searchScript = scriptService.search(context.lookup(), field.script(), ScriptContext.Standard.SEARCH,
|
||||
Collections.emptyMap());
|
||||
SearchScript searchScript = scriptService.search(context.lookup(), field.script(), ScriptContext.Standard.SEARCH);
|
||||
context.scriptFields().add(new ScriptField(field.fieldName(), searchScript, field.ignoreFailure()));
|
||||
}
|
||||
}
|
||||
|
@ -29,21 +29,19 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryShardException;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
import org.elasticsearch.search.aggregations.support.XContentParseContext;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptHeuristic extends SignificanceHeuristic {
|
||||
public static final String NAME = "script_heuristic";
|
||||
|
||||
private final Script script;
|
||||
|
||||
|
||||
// This class holds an executable form of the script with private variables ready for execution
|
||||
// on a single search thread.
|
||||
static class ExecutableScriptHeuristic extends ScriptHeuristic {
|
||||
@ -72,7 +70,7 @@ public class ScriptHeuristic extends SignificanceHeuristic {
|
||||
supersetSizeHolder.value = supersetSize;
|
||||
subsetDfHolder.value = subsetFreq;
|
||||
supersetDfHolder.value = supersetFreq;
|
||||
return ((Number) executableScript.run()).doubleValue();
|
||||
return ((Number) executableScript.run()).doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,12 +92,12 @@ public class ScriptHeuristic extends SignificanceHeuristic {
|
||||
|
||||
@Override
|
||||
public SignificanceHeuristic rewrite(InternalAggregation.ReduceContext context) {
|
||||
return new ExecutableScriptHeuristic(script, context.scriptService().executable(script, ScriptContext.Standard.AGGS, Collections.emptyMap()));
|
||||
return new ExecutableScriptHeuristic(script, context.scriptService().executable(script, ScriptContext.Standard.AGGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignificanceHeuristic rewrite(SearchContext context) {
|
||||
return new ExecutableScriptHeuristic(script, context.getQueryShardContext().getExecutableScript(script, ScriptContext.Standard.AGGS, Collections.emptyMap()));
|
||||
return new ExecutableScriptHeuristic(script, context.getQueryShardContext().getExecutableScript(script, ScriptContext.Standard.AGGS));
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +123,7 @@ public class ScriptHeuristic extends SignificanceHeuristic {
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field(ScriptField.SCRIPT.getPreferredName());
|
||||
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName());
|
||||
script.toXContent(builder, builderParams);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
@ -159,7 +157,7 @@ public class ScriptHeuristic extends SignificanceHeuristic {
|
||||
if (token.equals(XContentParser.Token.FIELD_NAME)) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if (context.matchField(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (context.matchField(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName);
|
||||
|
@ -191,17 +191,15 @@ public class ScriptedMetricAggregationBuilder extends AbstractAggregationBuilder
|
||||
QueryShardContext queryShardContext = context.searchContext().getQueryShardContext();
|
||||
Function<Map<String, Object>, ExecutableScript> executableInitScript;
|
||||
if (initScript != null) {
|
||||
executableInitScript = queryShardContext.getLazyExecutableScript(initScript, ScriptContext.Standard.AGGS,
|
||||
Collections.emptyMap());
|
||||
executableInitScript = queryShardContext.getLazyExecutableScript(initScript, ScriptContext.Standard.AGGS);
|
||||
} else {
|
||||
executableInitScript = (p) -> null;;
|
||||
}
|
||||
Function<Map<String, Object>, SearchScript> searchMapScript = queryShardContext.getLazySearchScript(mapScript,
|
||||
ScriptContext.Standard.AGGS, Collections.emptyMap());
|
||||
ScriptContext.Standard.AGGS);
|
||||
Function<Map<String, Object>, ExecutableScript> executableCombineScript;
|
||||
if (combineScript != null) {
|
||||
executableCombineScript = queryShardContext.getLazyExecutableScript(combineScript, ScriptContext.Standard.AGGS,
|
||||
Collections.emptyMap());
|
||||
executableCombineScript = queryShardContext.getLazyExecutableScript(combineScript, ScriptContext.Standard.AGGS);
|
||||
} else {
|
||||
executableCombineScript = (p) -> null;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ScriptedMetricAggregatorFactory extends AggregatorFactory<ScriptedM
|
||||
if (params != null) {
|
||||
params = deepCopyParams(params, context);
|
||||
}
|
||||
return new Script(script.getScript(), script.getType(), script.getLang(), params);
|
||||
return new Script(script.getType(), script.getLang(), script.getIdOrCode(), params);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||
if (scriptFields != null) {
|
||||
for (ScriptField field : scriptFields) {
|
||||
SearchScript searchScript = context.searchContext().getQueryShardContext().getSearchScript(field.script(),
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
ScriptContext.Standard.SEARCH);
|
||||
fields.add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
|
||||
field.fieldName(), searchScript, field.ignoreFailure()));
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
||||
@ -150,7 +149,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
|
||||
@Override
|
||||
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.field(BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
|
||||
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
||||
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName(), script);
|
||||
if (format != null) {
|
||||
builder.field(FORMAT.getPreferredName(), format);
|
||||
}
|
||||
@ -178,7 +177,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
|
||||
bucketsPathsMap.put("_value", parser.text());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
|
||||
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
@ -200,7 +199,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
|
||||
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
||||
Map<String, Object> map = parser.map();
|
||||
@ -223,7 +222,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
|
||||
}
|
||||
|
||||
if (script == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
|
||||
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + Script.SCRIPT_PARSE_FIELD.getPreferredName()
|
||||
+ "] for series_arithmetic aggregation [" + reducerName + "]");
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||
@ -119,7 +118,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
|
||||
@Override
|
||||
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.field(BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
|
||||
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
||||
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName(), script);
|
||||
builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
|
||||
return builder;
|
||||
}
|
||||
@ -141,7 +140,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
|
||||
bucketsPathsMap.put("_value", parser.text());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
|
||||
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
@ -163,7 +162,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
|
||||
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
|
||||
Map<String, Object> map = parser.map();
|
||||
@ -186,7 +185,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
|
||||
}
|
||||
|
||||
if (script == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
|
||||
throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + Script.SCRIPT_PARSE_FIELD.getPreferredName()
|
||||
+ "] for bucket_selector aggregation [" + reducerName + "]");
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
@ -133,7 +132,7 @@ public abstract class AbstractValuesSourceParser<VS extends ValuesSource>
|
||||
"Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "].");
|
||||
}
|
||||
} else if (scriptable && token == XContentParser.Token.START_OBJECT) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
|
||||
} else if (!token(aggregationName, currentFieldName, token, parserContext, otherOptions)) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
|
@ -376,7 +376,7 @@ public abstract class ValuesSourceAggregationBuilder<VS extends ValuesSource, AB
|
||||
if (script == null) {
|
||||
return null;
|
||||
} else {
|
||||
return context.getQueryShardContext().getSearchScript(script, ScriptContext.Standard.AGGS, Collections.emptyMap());
|
||||
return context.getQueryShardContext().getSearchScript(script, ScriptContext.Standard.AGGS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,14 +46,12 @@ import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.index.query.QueryShardException;
|
||||
import org.elasticsearch.script.LeafSearchScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.MultiValueMode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -218,7 +216,7 @@ public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder> {
|
||||
a -> new ScriptSortBuilder((Script) a[0], (ScriptSortType) a[1]));
|
||||
|
||||
static {
|
||||
PARSER.declareField(constructorArg(), Script::parse, ScriptField.SCRIPT, ValueType.OBJECT_OR_STRING);
|
||||
PARSER.declareField(constructorArg(), Script::parse, Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING);
|
||||
PARSER.declareField(constructorArg(), p -> ScriptSortType.fromString(p.text()), TYPE_FIELD, ValueType.STRING);
|
||||
PARSER.declareString((b, v) -> b.order(SortOrder.fromString(v)), ORDER_FIELD);
|
||||
PARSER.declareString((b, v) -> b.sortMode(SortMode.fromString(v)), SORTMODE_FIELD);
|
||||
@ -242,7 +240,7 @@ public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder> {
|
||||
|
||||
@Override
|
||||
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
|
||||
final SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
final SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
|
||||
|
||||
MultiValueMode valueMode = null;
|
||||
if (sortMode != null) {
|
||||
|
@ -393,7 +393,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionB
|
||||
* Sets a query used for filtering out suggested phrases (collation).
|
||||
*/
|
||||
public PhraseSuggestionBuilder collateQuery(String collateQuery) {
|
||||
this.collateQuery = new Script(collateQuery, ScriptType.INLINE, "mustache", Collections.emptyMap());
|
||||
this.collateQuery = new Script(ScriptType.INLINE, "mustache", collateQuery, Collections.emptyMap());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -635,7 +635,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionB
|
||||
|
||||
if (this.collateQuery != null) {
|
||||
Function<Map<String, Object>, ExecutableScript> compiledScript = context.getLazyExecutableScript(this.collateQuery,
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
ScriptContext.Standard.SEARCH);
|
||||
suggestionContext.setCollateQueryScript(compiledScript);
|
||||
if (this.collateParams != null) {
|
||||
suggestionContext.setCollateScriptParams(this.collateParams);
|
||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
||||
import org.elasticsearch.monitor.os.OsStats;
|
||||
import org.elasticsearch.index.query.SimpleQueryStringBuilder;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.internal.AliasFilter;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
@ -278,6 +279,8 @@ public class VersionTests extends ESTestCase {
|
||||
assertUnknownVersion(SimpleQueryStringBuilder.V_5_1_0_UNRELEASED);
|
||||
assertUnknownVersion(QueryStringQueryBuilder.V_5_1_0_UNRELEASED);
|
||||
// once we released 5.0.0 and it's added to Version.java we need to remove this constant
|
||||
assertUnknownVersion(Script.V_5_1_0_UNRELEASED);
|
||||
// once we released 5.0.0 and it's added to Version.java we need to remove this constant
|
||||
}
|
||||
|
||||
public static void assertUnknownVersion(Version version) {
|
||||
|
@ -259,7 +259,7 @@ public class IndicesRequestIT extends ESIntegTestCase {
|
||||
String indexOrAlias = randomIndexOrAlias();
|
||||
client().prepareIndex(indexOrAlias, "type", "id").setSource("field", "value").get();
|
||||
UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id")
|
||||
.script(new Script("ctx.op='delete'", ScriptType.INLINE, CustomScriptPlugin.NAME, Collections.emptyMap()));
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx.op='delete'", Collections.emptyMap()));
|
||||
UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet();
|
||||
assertEquals(DocWriteResponse.Result.DELETED, updateResponse.getResult());
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class BulkRequestTests extends ESTestCase {
|
||||
assertThat(((UpdateRequest) bulkRequest.requests().get(1)).index(), equalTo("index1"));
|
||||
Script script = ((UpdateRequest) bulkRequest.requests().get(1)).script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("counter += param1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("counter += param1"));
|
||||
assertThat(script.getLang(), equalTo("javascript"));
|
||||
Map<String, Object> scriptParams = script.getParams();
|
||||
assertThat(scriptParams, notNullValue());
|
||||
|
@ -122,7 +122,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
||||
assertThat(bulkItemResponse.getIndex(), equalTo("test"));
|
||||
}
|
||||
|
||||
final Script script = new Script("ctx._source.field += 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
final Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx._source.field += 1", Collections.emptyMap());
|
||||
|
||||
bulkResponse = client().prepareBulk()
|
||||
.add(client().prepareUpdate().setIndex(indexOrAlias()).setType("type1").setId("1").setScript(script))
|
||||
@ -259,11 +259,14 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
||||
|
||||
bulkResponse = client().prepareBulk()
|
||||
.add(client().prepareUpdate().setIndex("test").setType("type1").setId("1").setFields("field")
|
||||
.setScript(new Script("throw script exception on unknown var", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.setScript(new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "throw script exception on unknown var", Collections.emptyMap())))
|
||||
.add(client().prepareUpdate().setIndex("test").setType("type1").setId("2").setFields("field")
|
||||
.setScript(new Script("ctx._source.field += 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.setScript(new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx._source.field += 1", Collections.emptyMap())))
|
||||
.add(client().prepareUpdate().setIndex("test").setType("type1").setId("3").setFields("field")
|
||||
.setScript(new Script("throw script exception on unknown var", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.setScript(new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "throw script exception on unknown var", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(bulkResponse.hasFailures(), equalTo(true));
|
||||
@ -291,7 +294,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
||||
numDocs++; // this test needs an even num of docs
|
||||
}
|
||||
|
||||
final Script script = new Script("ctx._source.counter += 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
final Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx._source.counter += 1", Collections.emptyMap());
|
||||
|
||||
BulkRequestBuilder builder = client().prepareBulk();
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
@ -380,7 +383,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
||||
builder = client().prepareBulk();
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
builder.add(client().prepareUpdate().setIndex("test").setType("type1").setId(Integer.toString(i))
|
||||
.setScript(new Script("ctx.op = \"none\"", ScriptType.INLINE, CustomScriptPlugin.NAME, null)));
|
||||
.setScript(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx.op = \"none\"", Collections.emptyMap())));
|
||||
}
|
||||
response = builder.execute().actionGet();
|
||||
assertThat(response.buildFailureMessage(), response.hasFailures(), equalTo(false));
|
||||
@ -396,7 +399,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
||||
builder = client().prepareBulk();
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
builder.add(client().prepareUpdate().setIndex("test").setType("type1").setId(Integer.toString(i))
|
||||
.setScript(new Script("ctx.op = \"delete\"", ScriptType.INLINE, CustomScriptPlugin.NAME, null)));
|
||||
.setScript(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx.op = \"delete\"", Collections.emptyMap())));
|
||||
}
|
||||
response = builder.execute().actionGet();
|
||||
assertThat(response.hasFailures(), equalTo(false));
|
||||
|
@ -65,11 +65,11 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.endObject());
|
||||
Script script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
Map<String, Object> params = script.getParams();
|
||||
assertThat(params, nullValue());
|
||||
assertThat(params, equalTo(Collections.emptyMap()));
|
||||
|
||||
// simple verbose script
|
||||
request.fromXContent(XContentFactory.jsonBuilder().startObject()
|
||||
@ -77,11 +77,11 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.endObject());
|
||||
script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
params = script.getParams();
|
||||
assertThat(params, nullValue());
|
||||
assertThat(params, equalTo(Collections.emptyMap()));
|
||||
|
||||
// script with params
|
||||
request = new UpdateRequest("test", "type", "1");
|
||||
@ -94,7 +94,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.endObject().endObject());
|
||||
script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
params = script.getParams();
|
||||
@ -108,7 +108,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.field("inline", "script1").endObject().endObject());
|
||||
script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
params = script.getParams();
|
||||
@ -133,7 +133,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.endObject().endObject());
|
||||
script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
params = script.getParams();
|
||||
@ -160,7 +160,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
.endObject().endObject());
|
||||
script = request.script();
|
||||
assertThat(script, notNullValue());
|
||||
assertThat(script.getScript(), equalTo("script1"));
|
||||
assertThat(script.getIdOrCode(), equalTo("script1"));
|
||||
assertThat(script.getType(), equalTo(ScriptType.INLINE));
|
||||
assertThat(script.getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG));
|
||||
params = script.getParams();
|
||||
@ -325,7 +325,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
{
|
||||
UpdateRequest updateRequest = new UpdateRequest("test", "type1", "2")
|
||||
.upsert(indexRequest)
|
||||
.script(new Script("ctx._source.update_timestamp = ctx._now", ScriptType.INLINE, "mock", Collections.emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, "mock", "ctx._source.update_timestamp = ctx._now", Collections.emptyMap()))
|
||||
.scriptedUpsert(true);
|
||||
long nowInMillis = randomPositiveLong();
|
||||
// We simulate that the document is not existing yet
|
||||
@ -339,7 +339,7 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
{
|
||||
UpdateRequest updateRequest = new UpdateRequest("test", "type1", "2")
|
||||
.upsert(indexRequest)
|
||||
.script(new Script("ctx._timestamp = ctx._now", ScriptType.INLINE, "mock", Collections.emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, "mock", "ctx._timestamp = ctx._now", Collections.emptyMap()))
|
||||
.scriptedUpsert(true);
|
||||
long nowInMillis = randomPositiveLong();
|
||||
// We simulate that the document is not existing yet
|
||||
|
@ -40,6 +40,8 @@ import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertExists;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
@ -122,12 +124,14 @@ public class NoMasterNodeIT extends ESIntegTestCase {
|
||||
checkWriteAction(
|
||||
false, timeout,
|
||||
client().prepareUpdate("test", "type1", "1")
|
||||
.setScript(new Script("test script", ScriptType.INLINE, null, null)).setTimeout(timeout));
|
||||
.setScript(new Script(
|
||||
ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "test script", Collections.emptyMap())).setTimeout(timeout));
|
||||
|
||||
checkWriteAction(
|
||||
autoCreateIndex, timeout,
|
||||
client().prepareUpdate("no_index", "type1", "1")
|
||||
.setScript(new Script("test script", ScriptType.INLINE, null, null)).setTimeout(timeout));
|
||||
.setScript(new Script(
|
||||
ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "test script", Collections.emptyMap())).setTimeout(timeout));
|
||||
|
||||
|
||||
checkWriteAction(false, timeout,
|
||||
|
@ -24,6 +24,7 @@ import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@ -75,4 +76,30 @@ public class XContentParserTests extends ESTestCase {
|
||||
assertThat(e.getMessage(), containsString("Failed to parse list"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadMapStrings() throws IOException {
|
||||
Map<String, String> map = readMapStrings("{\"foo\": {\"kbar\":\"vbar\"}}");
|
||||
assertThat(map.get("kbar"), equalTo("vbar"));
|
||||
assertThat(map.size(), equalTo(1));
|
||||
map = readMapStrings("{\"foo\": {\"kbar\":\"vbar\", \"kbaz\":\"vbaz\"}}");
|
||||
assertThat(map.get("kbar"), equalTo("vbar"));
|
||||
assertThat(map.get("kbaz"), equalTo("vbaz"));
|
||||
assertThat(map.size(), equalTo(2));
|
||||
map = readMapStrings("{\"foo\": {}}");
|
||||
assertThat(map.size(), equalTo(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String> readMapStrings(String source) throws IOException {
|
||||
try (XContentParser parser = XContentType.JSON.xContent().createParser(source)) {
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
|
||||
token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
|
||||
assertThat(parser.currentName(), equalTo("foo"));
|
||||
token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
|
||||
return randomBoolean() ? parser.mapStringsOrdered() : parser.mapStrings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class WaitUntilRefreshIT extends ESIntegTestCase {
|
||||
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get(), "2");
|
||||
|
||||
// Update-becomes-delete with RefreshPolicy.WAIT_UNTIL
|
||||
update = client().prepareUpdate("test", "test", "2").setScript(new Script("delete_plz", ScriptType.INLINE, "native", emptyMap()))
|
||||
update = client().prepareUpdate("test", "test", "2").setScript(new Script(ScriptType.INLINE, "native", "delete_plz", emptyMap()))
|
||||
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
|
||||
assertEquals(2, update.getVersion());
|
||||
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
|
||||
|
@ -320,15 +320,14 @@ public class InnerHitBuilderTests extends ESTestCase {
|
||||
|
||||
static SearchSourceBuilder.ScriptField randomScript() {
|
||||
ScriptType randomScriptType = randomFrom(ScriptType.values());
|
||||
Map<String, Object> randomMap = null;
|
||||
Map<String, Object> randomMap = new HashMap<>();
|
||||
if (randomBoolean()) {
|
||||
randomMap = new HashMap<>();
|
||||
int numEntries = randomIntBetween(0, 32);
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
randomMap.put(String.valueOf(i), randomAsciiOfLength(16));
|
||||
}
|
||||
}
|
||||
Script script = new Script(randomAsciiOfLength(128), randomScriptType, randomAsciiOfLengthBetween(1, 4),randomMap);
|
||||
Script script = new Script(randomScriptType, randomAsciiOfLengthBetween(1, 4), randomAsciiOfLength(128), randomMap);
|
||||
return new SearchSourceBuilder.ScriptField(randomAsciiOfLengthBetween(1, 32), script, randomBoolean());
|
||||
}
|
||||
|
||||
|
@ -293,13 +293,11 @@ public class QueryDSLDocumentationTests extends ESTestCase {
|
||||
new Script("doc['num1'].value > 1")
|
||||
);
|
||||
|
||||
Map<String, Integer> parameters = new HashMap<>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("param1", 5);
|
||||
scriptQuery(
|
||||
new Script(
|
||||
"mygroovyscript",
|
||||
ScriptType.FILE,
|
||||
"groovy",
|
||||
ScriptType.FILE, "groovy", "mygroovyscript",
|
||||
parameters)
|
||||
);
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBu
|
||||
protected ScriptQueryBuilder doCreateTestQueryBuilder() {
|
||||
String script = "1";
|
||||
Map<String, Object> params = Collections.emptyMap();
|
||||
return new ScriptQueryBuilder(new Script(script, ScriptType.INLINE, MockScriptEngine.NAME, params));
|
||||
return new ScriptQueryBuilder(new Script(ScriptType.INLINE, MockScriptEngine.NAME, script, params));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,8 +67,7 @@ public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBu
|
||||
" \"script\" : {\n" +
|
||||
" \"script\" : {\n" +
|
||||
" \"inline\" : \"5\",\n" +
|
||||
" \"lang\" : \"mockscript\",\n" +
|
||||
" \"params\" : { }\n" +
|
||||
" \"lang\" : \"mockscript\"\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 1.0,\n" +
|
||||
" \"_name\" : \"PcKdEyPOmR\"\n" +
|
||||
@ -92,14 +91,14 @@ public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBu
|
||||
"}";
|
||||
|
||||
ScriptQueryBuilder parsed = (ScriptQueryBuilder) parseQuery(json);
|
||||
assertEquals(json, "5", parsed.script().getScript());
|
||||
assertEquals(json, "5", parsed.script().getIdOrCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getObjectsHoldingArbitraryContent() {
|
||||
//script_score.script.params can contain arbitrary parameters. no error is expected when
|
||||
//adding additional objects within the params object.
|
||||
return Collections.singleton(Script.ScriptField.PARAMS.getPreferredName());
|
||||
return Collections.singleton(Script.PARAMS_PARSE_FIELD.getPreferredName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,7 +109,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
||||
protected Set<String> getObjectsHoldingArbitraryContent() {
|
||||
//script_score.script.params can contain arbitrary parameters. no error is expected when adding additional objects
|
||||
//within the params object. Score functions get parsed in the data nodes, so they are not validated in the coord node.
|
||||
return new HashSet<>(Arrays.asList(Script.ScriptField.PARAMS.getPreferredName(), ExponentialDecayFunctionBuilder.NAME,
|
||||
return new HashSet<>(Arrays.asList(Script.PARAMS_PARSE_FIELD.getPreferredName(), ExponentialDecayFunctionBuilder.NAME,
|
||||
LinearDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder.NAME));
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
||||
String script = "1";
|
||||
Map<String, Object> params = Collections.emptyMap();
|
||||
functionBuilder = new ScriptScoreFunctionBuilder(
|
||||
new Script(script, ScriptType.INLINE, MockScriptEngine.NAME, params));
|
||||
new Script(ScriptType.INLINE, MockScriptEngine.NAME, script, params));
|
||||
break;
|
||||
case 3:
|
||||
RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilderWithFixedSeed();
|
||||
|
@ -54,7 +54,7 @@ public class FileScriptTests extends ESTestCase {
|
||||
Settings settings = Settings.builder()
|
||||
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false").build();
|
||||
ScriptService scriptService = makeScriptService(settings);
|
||||
Script script = new Script("script1", ScriptType.FILE, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(ScriptType.FILE, MockScriptEngine.NAME, "script1", Collections.emptyMap());
|
||||
CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
assertNotNull(compiledScript);
|
||||
MockCompiledScript executable = (MockCompiledScript) compiledScript.compiled();
|
||||
@ -69,7 +69,7 @@ public class FileScriptTests extends ESTestCase {
|
||||
.put("script.engine." + MockScriptEngine.NAME + ".file.update", "false")
|
||||
.put("script.engine." + MockScriptEngine.NAME + ".file.ingest", "false").build();
|
||||
ScriptService scriptService = makeScriptService(settings);
|
||||
Script script = new Script("script1", ScriptType.FILE, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(ScriptType.FILE, MockScriptEngine.NAME, "script1", Collections.emptyMap());
|
||||
for (ScriptContext context : ScriptContext.Standard.values()) {
|
||||
try {
|
||||
scriptService.compile(script, context, Collections.emptyMap());
|
||||
|
@ -683,7 +683,7 @@ public class IndexLookupIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
private Script createScript(String script) {
|
||||
return new Script(script, ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
return new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, script, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public void testFlags() throws Exception {
|
||||
|
@ -53,8 +53,7 @@ public class NativeScriptTests extends ESTestCase {
|
||||
scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
|
||||
|
||||
ExecutableScript executable = scriptModule.getScriptService().executable(
|
||||
new Script("my", ScriptType.INLINE, NativeScriptEngineService.NAME, null), ScriptContext.Standard.SEARCH,
|
||||
Collections.emptyMap());
|
||||
new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "my", Collections.emptyMap()), ScriptContext.Standard.SEARCH);
|
||||
assertThat(executable.run().toString(), equalTo("test"));
|
||||
}
|
||||
|
||||
@ -80,8 +79,8 @@ public class NativeScriptTests extends ESTestCase {
|
||||
scriptContextRegistry, scriptSettings);
|
||||
|
||||
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
|
||||
assertThat(scriptService.compile(new Script("my", ScriptType.INLINE, NativeScriptEngineService.NAME, null), scriptContext,
|
||||
Collections.emptyMap()), notNullValue());
|
||||
assertThat(scriptService.compile(new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "my", Collections.emptyMap()),
|
||||
scriptContext, Collections.emptyMap()), notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class ScriptContextTests extends ESTestCase {
|
||||
ScriptService scriptService = makeScriptService();
|
||||
for (ScriptType scriptType : ScriptType.values()) {
|
||||
try {
|
||||
Script script = new Script("1", scriptType, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(scriptType, MockScriptEngine.NAME, "1", Collections.emptyMap());
|
||||
scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"), Collections.emptyMap());
|
||||
fail("script compilation should have been rejected");
|
||||
} catch (IllegalStateException e) {
|
||||
@ -69,7 +69,7 @@ public class ScriptContextTests extends ESTestCase {
|
||||
|
||||
public void testCustomScriptContextSettings() throws Exception {
|
||||
ScriptService scriptService = makeScriptService();
|
||||
Script script = new Script("1", ScriptType.INLINE, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, MockScriptEngine.NAME, "1", Collections.emptyMap());
|
||||
try {
|
||||
scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"), Collections.emptyMap());
|
||||
fail("script compilation should have been rejected");
|
||||
@ -87,7 +87,7 @@ public class ScriptContextTests extends ESTestCase {
|
||||
ScriptService scriptService = makeScriptService();
|
||||
for (ScriptType scriptType : ScriptType.values()) {
|
||||
try {
|
||||
Script script = new Script("1", scriptType, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(scriptType, MockScriptEngine.NAME, "1", Collections.emptyMap());
|
||||
scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "unknown"), Collections.emptyMap());
|
||||
fail("script compilation should have been rejected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -106,7 +106,7 @@ public class ScriptContextTests extends ESTestCase {
|
||||
ScriptService scriptService = makeScriptService();
|
||||
for (ScriptType scriptType : ScriptType.values()) {
|
||||
try {
|
||||
Script script = new Script("1", scriptType, MockScriptEngine.NAME, null);
|
||||
Script script = new Script(scriptType, MockScriptEngine.NAME, "1", Collections.emptyMap());
|
||||
scriptService.compile(script, context, Collections.emptyMap());
|
||||
fail("script compilation should have been rejected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -60,10 +61,10 @@ public class ScriptFieldIT extends ESIntegTestCase {
|
||||
|
||||
client().admin().indices().prepareFlush("test").execute().actionGet();
|
||||
SearchResponse sr = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
||||
.addScriptField("int", new Script("int", ScriptType.INLINE, "native", null))
|
||||
.addScriptField("float", new Script("float", ScriptType.INLINE, "native", null))
|
||||
.addScriptField("double", new Script("double", ScriptType.INLINE, "native", null))
|
||||
.addScriptField("long", new Script("long", ScriptType.INLINE, "native", null)).execute().actionGet();
|
||||
.addScriptField("int", new Script(ScriptType.INLINE, "native", "int", Collections.emptyMap()))
|
||||
.addScriptField("float", new Script(ScriptType.INLINE, "native", "float", Collections.emptyMap()))
|
||||
.addScriptField("double", new Script(ScriptType.INLINE, "native", "double", Collections.emptyMap()))
|
||||
.addScriptField("long", new Script(ScriptType.INLINE, "native", "long", Collections.emptyMap())).execute().actionGet();
|
||||
assertThat(sr.getHits().hits().length, equalTo(6));
|
||||
for (SearchHit hit : sr.getHits().getHits()) {
|
||||
Object result = hit.getFields().get("int").getValues().get(0);
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import com.sun.javafx.collections.ElementObservableListDecorator;
|
||||
import org.elasticsearch.ResourceNotFoundException;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
@ -169,7 +170,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
Streams.copy("test_file".getBytes("UTF-8"), Files.newOutputStream(testFileWithExt));
|
||||
resourceWatcherService.notifyNow();
|
||||
|
||||
CompiledScript compiledScript = scriptService.compile(new Script("test_script", ScriptType.FILE, "test", null),
|
||||
CompiledScript compiledScript = scriptService.compile(new Script(ScriptType.FILE, "test", "test_script", Collections.emptyMap()),
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file"));
|
||||
|
||||
@ -178,7 +179,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
resourceWatcherService.notifyNow();
|
||||
|
||||
try {
|
||||
scriptService.compile(new Script("test_script", ScriptType.FILE, "test", null), ScriptContext.Standard.SEARCH,
|
||||
scriptService.compile(new Script(ScriptType.FILE, "test", "test_script", Collections.emptyMap()), ScriptContext.Standard.SEARCH,
|
||||
Collections.emptyMap());
|
||||
fail("the script test_script should no longer exist");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
@ -196,7 +197,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
Streams.copy("test_file_script".getBytes("UTF-8"), Files.newOutputStream(testFileScript));
|
||||
resourceWatcherService.notifyNow();
|
||||
|
||||
CompiledScript compiledScript = scriptService.compile(new Script("file_script", ScriptType.FILE, "test", null),
|
||||
CompiledScript compiledScript = scriptService.compile(new Script(ScriptType.FILE, "test", "file_script", Collections.emptyMap()),
|
||||
ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file_script"));
|
||||
|
||||
@ -207,9 +208,9 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
public void testInlineScriptCompiledOnceCache() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
CompiledScript compiledScript1 = scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null),
|
||||
CompiledScript compiledScript1 = scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()),
|
||||
randomFrom(scriptContexts), Collections.emptyMap());
|
||||
CompiledScript compiledScript2 = scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null),
|
||||
CompiledScript compiledScript2 = scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()),
|
||||
randomFrom(scriptContexts), Collections.emptyMap());
|
||||
assertThat(compiledScript1.compiled(), sameInstance(compiledScript2.compiled()));
|
||||
}
|
||||
@ -332,8 +333,8 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
String type = scriptEngineService.getType();
|
||||
try {
|
||||
scriptService.compile(new Script("test", randomFrom(ScriptType.values()), type, null), new ScriptContext.Plugin(
|
||||
pluginName, unknownContext), Collections.emptyMap());
|
||||
scriptService.compile(new Script(randomFrom(ScriptType.values()), type, "test", Collections.emptyMap()),
|
||||
new ScriptContext.Plugin(pluginName, unknownContext), Collections.emptyMap());
|
||||
fail("script compilation should have been rejected");
|
||||
} catch(IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("script context [" + pluginName + "_" + unknownContext + "] not supported"));
|
||||
@ -342,21 +343,20 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
public void testCompileCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts),
|
||||
scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts),
|
||||
Collections.emptyMap());
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
public void testExecutableCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
|
||||
scriptService.executable(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
public void testSearchCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
scriptService.search(null, new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts),
|
||||
Collections.emptyMap());
|
||||
scriptService.search(null, new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
@ -365,7 +365,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
int numberOfCompilations = randomIntBetween(1, 1024);
|
||||
for (int i = 0; i < numberOfCompilations; i++) {
|
||||
scriptService
|
||||
.compile(new Script(i + " + " + i, ScriptType.INLINE, "test", null), randomFrom(scriptContexts),
|
||||
.compile(new Script(ScriptType.INLINE, "test", i + " + " + i, Collections.emptyMap()), randomFrom(scriptContexts),
|
||||
Collections.emptyMap());
|
||||
}
|
||||
assertEquals(numberOfCompilations, scriptService.stats().getCompilations());
|
||||
@ -376,22 +376,22 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), 1);
|
||||
builder.put("script.inline", "true");
|
||||
buildScriptService(builder.build());
|
||||
scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
|
||||
scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
|
||||
scriptService.executable(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
scriptService.executable(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
public void testFileScriptCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
createFileScripts("test");
|
||||
scriptService.compile(new Script("file_script", ScriptType.FILE, "test", null), randomFrom(scriptContexts),
|
||||
scriptService.compile(new Script(ScriptType.FILE, "test", "file_script", Collections.emptyMap()), randomFrom(scriptContexts),
|
||||
Collections.emptyMap());
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
|
||||
public void testIndexedScriptCountedInCompilationStats() throws IOException {
|
||||
buildScriptService(Settings.EMPTY);
|
||||
scriptService.compile(new Script("script", ScriptType.STORED, "test", null), randomFrom(scriptContexts),
|
||||
scriptService.compile(new Script(ScriptType.STORED, "test", "script", Collections.emptyMap()), randomFrom(scriptContexts),
|
||||
Collections.emptyMap());
|
||||
assertEquals(1L, scriptService.stats().getCompilations());
|
||||
}
|
||||
@ -401,8 +401,8 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), 1);
|
||||
builder.put("script.inline", "true");
|
||||
buildScriptService(builder.build());
|
||||
scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
|
||||
scriptService.executable(new Script("2+2", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
|
||||
scriptService.executable(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
scriptService.executable(new Script(ScriptType.INLINE, "test", "2+2", Collections.emptyMap()), randomFrom(scriptContexts));
|
||||
assertEquals(2L, scriptService.stats().getCompilations());
|
||||
assertEquals(1L, scriptService.stats().getCacheEvictions());
|
||||
}
|
||||
@ -411,7 +411,8 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
builder.put("script.inline", "true");
|
||||
buildScriptService(builder.build());
|
||||
CompiledScript script = scriptService.compile(new Script("1 + 1", ScriptType.INLINE, null, null),
|
||||
CompiledScript script = scriptService.compile(
|
||||
new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "1 + 1", Collections.emptyMap()),
|
||||
randomFrom(scriptContexts), Collections.emptyMap());
|
||||
assertEquals(script.lang(), Script.DEFAULT_SCRIPT_LANG);
|
||||
}
|
||||
@ -493,7 +494,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) {
|
||||
try {
|
||||
scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, Collections.emptyMap());
|
||||
scriptService.compile(new Script(scriptType, lang, script, Collections.emptyMap()), scriptContext, Collections.emptyMap());
|
||||
fail("compile should have been rejected for lang [" + lang + "], script_type [" + scriptType + "], scripted_op [" + scriptContext + "]");
|
||||
} catch(IllegalStateException e) {
|
||||
//all good
|
||||
@ -502,7 +503,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
private void assertCompileAccepted(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) {
|
||||
assertThat(
|
||||
scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, Collections.emptyMap()),
|
||||
scriptService.compile(new Script(scriptType, lang, script, Collections.emptyMap()), scriptContext, Collections.emptyMap()),
|
||||
notNullValue()
|
||||
);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class ScriptTests extends ESTestCase {
|
||||
}
|
||||
|
||||
private Script createScript(XContent xContent) throws IOException {
|
||||
final Map<String, Object> params = randomBoolean() ? null : Collections.singletonMap("key", "value");
|
||||
final Map<String, Object> params = randomBoolean() ? Collections.emptyMap() : Collections.singletonMap("key", "value");
|
||||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
String script;
|
||||
if (scriptType == ScriptType.INLINE) {
|
||||
@ -79,11 +79,12 @@ public class ScriptTests extends ESTestCase {
|
||||
script = randomAsciiOfLengthBetween(1, 5);
|
||||
}
|
||||
return new Script(
|
||||
script,
|
||||
scriptType,
|
||||
randomFrom("_lang1", "_lang2", null),
|
||||
params,
|
||||
scriptType == ScriptType.INLINE ? xContent.type() : null
|
||||
scriptType,
|
||||
randomFrom("_lang1", "_lang2", "_lang3"),
|
||||
script,
|
||||
scriptType == ScriptType.INLINE ?
|
||||
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, xContent.type().mediaType()) : Collections.emptyMap(),
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,8 @@ public class SearchCancellationIT extends ESIntegTestCase {
|
||||
|
||||
logger.info("Executing search");
|
||||
ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test").setQuery(
|
||||
scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null)))
|
||||
scriptQuery(new Script(
|
||||
ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
|
||||
.execute();
|
||||
|
||||
awaitForBlock(plugins);
|
||||
@ -165,7 +166,7 @@ public class SearchCancellationIT extends ESIntegTestCase {
|
||||
logger.info("Executing search");
|
||||
ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test")
|
||||
.addScriptField("test_field",
|
||||
new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null)
|
||||
new Script(ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())
|
||||
).execute();
|
||||
|
||||
awaitForBlock(plugins);
|
||||
@ -186,7 +187,8 @@ public class SearchCancellationIT extends ESIntegTestCase {
|
||||
.setScroll(TimeValue.timeValueSeconds(10))
|
||||
.setSize(5)
|
||||
.setQuery(
|
||||
scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null)))
|
||||
scriptQuery(new Script(
|
||||
ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
|
||||
.execute();
|
||||
|
||||
awaitForBlock(plugins);
|
||||
@ -211,7 +213,8 @@ public class SearchCancellationIT extends ESIntegTestCase {
|
||||
.setScroll(keepAlive)
|
||||
.setSize(2)
|
||||
.setQuery(
|
||||
scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null)))
|
||||
scriptQuery(new Script(
|
||||
ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertNotNull(searchResponse.getScrollId());
|
||||
|
@ -58,7 +58,8 @@ public class SearchTimeoutIT extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setTimeout(new TimeValue(10, TimeUnit.MILLISECONDS))
|
||||
.setQuery(scriptQuery(new Script(NativeTestScriptedTimeout.TEST_NATIVE_SCRIPT_TIMEOUT, ScriptType.INLINE, "native", null)))
|
||||
.setQuery(scriptQuery(
|
||||
new Script(ScriptType.INLINE, "native", NativeTestScriptedTimeout.TEST_NATIVE_SCRIPT_TIMEOUT, Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
assertThat(searchResponse.isTimedOut(), equalTo(true));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class AggregationTestScriptsPlugin extends MockScriptPlugin {
|
||||
// res[i] = values.get(i) - dec;
|
||||
// };
|
||||
// return res;
|
||||
public static final Script DECREMENT_ALL_VALUES = new Script("decrement all values", ScriptType.INLINE, NAME, singletonMap("dec", 1));
|
||||
public static final Script DECREMENT_ALL_VALUES = new Script(ScriptType.INLINE, NAME, "decrement all values", singletonMap("dec", 1));
|
||||
|
||||
@Override
|
||||
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
|
||||
@ -91,7 +91,7 @@ public class AggregationTestScriptsPlugin extends MockScriptPlugin {
|
||||
return doc.get("values");
|
||||
});
|
||||
|
||||
scripts.put(DECREMENT_ALL_VALUES.getScript(), vars -> {
|
||||
scripts.put(DECREMENT_ALL_VALUES.getIdOrCode(), vars -> {
|
||||
int dec = (int) vars.get("dec");
|
||||
Map<?, ?> doc = (Map) vars.get("doc");
|
||||
ScriptDocValues.Longs values = (ScriptDocValues.Longs) doc.get("values");
|
||||
|
@ -383,7 +383,7 @@ public class EquivalenceIT extends ESIntegTestCase {
|
||||
terms("terms")
|
||||
.field("values")
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("floor(_value / interval)", ScriptType.INLINE, CustomScriptPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "floor(_value / interval)", params))
|
||||
.size(maxNumTerms))
|
||||
.addAggregation(
|
||||
histogram("histo")
|
||||
|
@ -496,7 +496,7 @@ public class DateHistogramIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateHistogram("histo")
|
||||
.field("date")
|
||||
.script(new Script(DateScriptMocks.PlusOneMonthScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
|
||||
.dateHistogramInterval(DateHistogramInterval.MONTH)).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -632,7 +632,7 @@ public class DateHistogramIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateHistogram("histo")
|
||||
.field("dates")
|
||||
.script(new Script(DateScriptMocks.PlusOneMonthScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
|
||||
.dateHistogramInterval(DateHistogramInterval.MONTH)).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -684,8 +684,8 @@ public class DateHistogramIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldname", "date");
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateHistogram("histo").script(new Script(DateScriptMocks.ExtractFieldScript.NAME,
|
||||
ScriptType.INLINE, "native", params)).dateHistogramInterval(DateHistogramInterval.MONTH))
|
||||
.addAggregation(dateHistogram("histo").script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME,
|
||||
params)).dateHistogramInterval(DateHistogramInterval.MONTH))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -722,8 +722,8 @@ public class DateHistogramIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldname", "dates");
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateHistogram("histo").script(new Script(DateScriptMocks.ExtractFieldScript.NAME,
|
||||
ScriptType.INLINE, "native", params)).dateHistogramInterval(DateHistogramInterval.MONTH))
|
||||
.addAggregation(dateHistogram("histo").script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME,
|
||||
params)).dateHistogramInterval(DateHistogramInterval.MONTH))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -1214,7 +1214,7 @@ public class DateHistogramIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldname", "d");
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(dateHistogram("histo").field("d")
|
||||
.script(new Script(DateScriptMocks.PlusOneMonthScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
|
||||
.dateHistogramInterval(DateHistogramInterval.MONTH)).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class DateRangeIT extends ESIntegTestCase {
|
||||
if (randomBoolean()) {
|
||||
rangeBuilder.field("date");
|
||||
} else {
|
||||
rangeBuilder.script(new Script(DateScriptMocks.ExtractFieldScript.NAME, ScriptType.INLINE, "native", params));
|
||||
rangeBuilder.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params));
|
||||
}
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -541,7 +541,7 @@ public class DateRangeIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateRange("range")
|
||||
.field("dates")
|
||||
.script(new Script(DateScriptMocks.PlusOneMonthScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
|
||||
.addUnboundedTo(date(2, 15)).addRange(date(2, 15), date(3, 15)).addUnboundedFrom(date(3, 15))).execute()
|
||||
.actionGet();
|
||||
|
||||
@ -597,7 +597,7 @@ public class DateRangeIT extends ESIntegTestCase {
|
||||
params.put("fieldname", "date");
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(dateRange("range")
|
||||
.script(new Script(DateScriptMocks.ExtractFieldScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params))
|
||||
.addUnboundedTo(date(2, 15))
|
||||
.addRange(date(2, 15), date(3, 15))
|
||||
.addUnboundedFrom(date(3, 15)))
|
||||
@ -659,7 +659,7 @@ public class DateRangeIT extends ESIntegTestCase {
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
.addAggregation(
|
||||
dateRange("range").script(new Script(DateScriptMocks.ExtractFieldScript.NAME, ScriptType.INLINE, "native", params))
|
||||
dateRange("range").script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params))
|
||||
.addUnboundedTo(date(2, 15)).addRange(date(2, 15), date(3, 15))
|
||||
.addUnboundedFrom(date(3, 15))).execute().actionGet();
|
||||
|
||||
@ -889,7 +889,7 @@ public class DateRangeIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldname", "date");
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(dateRange("foo").field("date")
|
||||
.script(new Script(DateScriptMocks.PlusOneMonthScript.NAME, ScriptType.INLINE, "native", params))
|
||||
.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
|
||||
.addRange(new DateTime(2012, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC), new DateTime(2013, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC)))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
@ -452,7 +452,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -505,7 +505,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -534,7 +534,8 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("(long) (_value / 1000 + 1)", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "(long) (_value / 1000 + 1)", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -576,8 +577,8 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(
|
||||
terms("terms")
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("doc['" + MULTI_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "'].value", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -603,8 +604,8 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(
|
||||
terms("terms")
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("doc['" + MULTI_VALUED_FIELD_NAME + "']", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "']",
|
||||
Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -1078,10 +1079,11 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
}
|
||||
|
||||
public void testScriptScore() {
|
||||
Script scoringScript =
|
||||
new Script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE, CustomScriptPlugin .NAME, null);
|
||||
Script scoringScript = new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin .NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap());
|
||||
|
||||
Script aggregationScript = new Script("ceil(_score.doubleValue()/3)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script aggregationScript = new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "ceil(_score.doubleValue()/3)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -1200,7 +1202,8 @@ public class DoubleTermsIT extends AbstractTermsTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
terms("terms").field("d").script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))).get();
|
||||
terms("terms").field("d").script(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -562,7 +562,7 @@ public class HistogramIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
histogram("histo")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", emptyMap()))
|
||||
.interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -639,7 +639,7 @@ public class HistogramIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
histogram("histo")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", emptyMap()))
|
||||
.interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -675,7 +675,7 @@ public class HistogramIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(
|
||||
histogram("histo")
|
||||
.script(new Script("doc['l_value'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['l_value'].value", emptyMap()))
|
||||
.interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -699,7 +699,7 @@ public class HistogramIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(
|
||||
histogram("histo")
|
||||
.script(new Script("doc['l_values']", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['l_values']", emptyMap()))
|
||||
.interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -1016,7 +1016,7 @@ public class HistogramIT extends ESIntegTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(histogram("histo").field("d")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())).interval(0.7).offset(0.05)).get();
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", emptyMap())).interval(0.7).offset(0.05)).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -208,7 +208,7 @@ public class IpRangeIT extends ESIntegTestCase {
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> client().prepareSearch("idx").addAggregation(
|
||||
AggregationBuilders.ipRange("my_range")
|
||||
.script(new Script(DummyScript.NAME, ScriptType.INLINE, "native", Collections.emptyMap())) ).get());
|
||||
.script(new Script(ScriptType.INLINE, "native", DummyScript.NAME, Collections.emptyMap())) ).get());
|
||||
assertThat(e.getMessage(), containsString("[ip_range] does not support scripts"));
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ public class IpRangeIT extends ESIntegTestCase {
|
||||
() -> client().prepareSearch("idx").addAggregation(
|
||||
AggregationBuilders.ipRange("my_range")
|
||||
.field("ip")
|
||||
.script(new Script(DummyScript.NAME, ScriptType.INLINE, "native", Collections.emptyMap())) ).get());
|
||||
.script(new Script(ScriptType.INLINE, "native", DummyScript.NAME, Collections.emptyMap())) ).get());
|
||||
assertThat(e.getMessage(), containsString("[ip_range] does not support scripts"));
|
||||
}
|
||||
|
||||
|
@ -442,7 +442,7 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -495,7 +495,7 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value - 1", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -524,7 +524,8 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(terms("terms")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("floor(_value / 1000 + 1)", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "floor(_value / 1000 + 1)", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -560,7 +561,8 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
*/
|
||||
|
||||
public void testScriptSingleValue() throws Exception {
|
||||
Script script = new Script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
@ -586,7 +588,8 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
}
|
||||
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
Script script = new Script("doc['" + MULTI_VALUED_FIELD_NAME + "']", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "']", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
@ -1157,7 +1160,8 @@ public class LongTermsIT extends AbstractTermsTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
terms("terms").field("d").script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))).get();
|
||||
terms("terms").field("d").script(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -151,8 +151,8 @@ public class MinDocCountIT extends AbstractTermsTestCase {
|
||||
YES {
|
||||
@Override
|
||||
TermsAggregationBuilder apply(TermsAggregationBuilder builder, String field) {
|
||||
return builder.script(new org.elasticsearch.script.Script("doc['" + field + "'].values", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null));
|
||||
return builder.script(new org.elasticsearch.script.Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "doc['" + field + "'].values", Collections.emptyMap()));
|
||||
}
|
||||
};
|
||||
abstract TermsAggregationBuilder apply(TermsAggregationBuilder builder, String field);
|
||||
|
@ -394,7 +394,7 @@ public class RangeIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
range("range")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap()))
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
@ -514,7 +514,7 @@ public class RangeIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
range("range")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap()))
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
@ -575,7 +575,8 @@ public class RangeIT extends ESIntegTestCase {
|
||||
*/
|
||||
|
||||
public void testScriptSingleValue() throws Exception {
|
||||
Script script = new Script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap());
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
.addAggregation(
|
||||
@ -660,7 +661,8 @@ public class RangeIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
Script script = new Script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "'].values", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -933,7 +935,8 @@ public class RangeIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldname", "date");
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
range("foo").field("i").script(new Script("_value + 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)).addRange(0, 10))
|
||||
range("foo").field("i").script(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value + 1", Collections.emptyMap())).addRange(0, 10))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -56,6 +56,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -507,14 +508,13 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
private ScriptHeuristic getScriptSignificanceHeuristic() throws IOException {
|
||||
Script script = null;
|
||||
Script script;
|
||||
if (randomBoolean()) {
|
||||
Map<String, Object> params = null;
|
||||
params = new HashMap<>();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("param", randomIntBetween(1, 100));
|
||||
script = new Script("native_significance_score_script_with_params", ScriptType.INLINE, "native", params);
|
||||
script = new Script(ScriptType.INLINE, "native", "native_significance_score_script_with_params", params);
|
||||
} else {
|
||||
script = new Script("native_significance_score_script_no_params", ScriptType.INLINE, "native", null);
|
||||
script = new Script(ScriptType.INLINE, "native", "native_significance_score_script_no_params", Collections.emptyMap());
|
||||
}
|
||||
return new ScriptHeuristic(script);
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
.executionHint(randomExecutionHint())
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("'foo_' + _value", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "'foo_' + _value", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -602,7 +602,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
.executionHint(randomExecutionHint())
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("_value.substring(0,3)", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(
|
||||
ScriptType.INLINE, CustomScriptPlugin.NAME, "_value.substring(0,3)", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -652,7 +653,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
.addAggregation(
|
||||
terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script(new Script("doc['" + MULTI_VALUED_FIELD_NAME + "']", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "']", Collections.emptyMap()))
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values())))
|
||||
.get();
|
||||
|
||||
@ -684,7 +686,7 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
.executionHint(randomExecutionHint())
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.script(new Script("'foo_' + _value", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "'foo_' + _value", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -719,7 +721,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
*/
|
||||
|
||||
public void testScriptSingleValue() throws Exception {
|
||||
Script script = new Script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -747,7 +750,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
}
|
||||
|
||||
public void testScriptSingleValueExplicitSingleValue() throws Exception {
|
||||
Script script = new Script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -782,7 +786,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
terms("terms")
|
||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||
.executionHint(randomExecutionHint())
|
||||
.script(new Script("doc['" + MULTI_VALUED_FIELD_NAME + "']", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "']", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -1533,7 +1538,8 @@ public class StringTermsIT extends AbstractTermsTestCase {
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(
|
||||
terms("terms").field("d").script(new Script("'foo_' + _value", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
terms("terms").field("d").script(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "'foo_' + _value", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg").field("value")
|
||||
.script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -184,7 +184,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg").field("value")
|
||||
.script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -228,7 +228,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg").field("values")
|
||||
.script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -245,7 +245,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg").field("values")
|
||||
.script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -261,7 +261,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg")
|
||||
.script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "value", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -278,7 +278,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg")
|
||||
.script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "value", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -294,7 +294,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg")
|
||||
.script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "values", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -311,7 +311,7 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg")
|
||||
.script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "values", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -371,7 +371,8 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(avg("foo").field("d").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).get();
|
||||
.addAggregation(avg("foo").field("d").script(
|
||||
new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -306,7 +306,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.script(new Script("doc['str_value'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['str_value'].value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -322,7 +322,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.script(new Script("doc['str_values'].values", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['str_values'].values", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -334,7 +334,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testSingleValuedNumericScript() throws Exception {
|
||||
Script script = new Script("doc[' + singleNumericField() + '].value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap());
|
||||
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();
|
||||
@ -348,7 +348,8 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testMultiValuedNumericScript() throws Exception {
|
||||
Script script = new Script("doc[' + multiNumericField(false) + '].values", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc[' + multiNumericField(false) + '].values", Collections.emptyMap());
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(script))
|
||||
.execute().actionGet();
|
||||
@ -367,7 +368,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.field("str_value")
|
||||
.script(new Script("_value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -384,7 +385,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.field("str_values")
|
||||
.script(new Script("_value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -401,7 +402,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.field(singleNumericField())
|
||||
.script(new Script("_value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -418,7 +419,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
cardinality("cardinality")
|
||||
.precisionThreshold(precisionThreshold)
|
||||
.field(multiNumericField(false))
|
||||
.script(new Script("_value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -467,7 +468,7 @@ public class CardinalityIT extends ESIntegTestCase {
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(
|
||||
cardinality("foo").field("d").script(new Script("_value", ScriptType.INLINE, CustomScriptPlugin.NAME, emptyMap())))
|
||||
cardinality("foo").field("d").script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -301,7 +301,8 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.field("value")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, "_value + 1", Collections.emptyMap()))
|
||||
.sigma(sigma))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -331,7 +332,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.field("value")
|
||||
.script(new Script("_value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + inc", params))
|
||||
.sigma(sigma))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -383,7 +384,8 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, "_value - 1", Collections.emptyMap()))
|
||||
.sigma(sigma))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -413,7 +415,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.sigma(sigma))
|
||||
.get();
|
||||
|
||||
@ -440,7 +442,8 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, "doc['value'].value", Collections.emptyMap()))
|
||||
.sigma(sigma))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -465,7 +468,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("inc", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value + inc", params);
|
||||
|
||||
double sigma = randomDouble() * randomIntBetween(1, 10);
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
@ -499,7 +502,8 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
extendedStats("stats")
|
||||
.script(new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, "doc['values'].values", Collections.emptyMap()))
|
||||
.sigma(sigma))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -524,8 +528,8 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("[ doc['value'].value, doc['value'].value - dec ]", ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "[ doc['value'].value, doc['value'].value - dec ]",
|
||||
params);
|
||||
|
||||
double sigma = randomDouble() * randomIntBetween(1, 10);
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
@ -653,7 +657,7 @@ public class ExtendedStatsIT extends AbstractNumericTestCase {
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(extendedStats("foo").field("d")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -260,7 +260,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.field("value")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -284,7 +284,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.field("value")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -324,7 +324,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -345,7 +345,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.field("values")
|
||||
.script(new Script("20 - _value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "20 - _value", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -369,7 +369,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -390,7 +390,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
percentileRanks("percentile_ranks")
|
||||
.method(PercentilesMethod.HDR)
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -406,7 +406,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
|
||||
|
||||
final double[] pcts = randomPercents(minValue - 1, maxValue - 1);
|
||||
SearchResponse searchResponse = client()
|
||||
@ -431,7 +431,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
int sigDigits = randomSignificantDigits();
|
||||
final double[] pcts = randomPercents(minValues, maxValues);
|
||||
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client()
|
||||
.prepareSearch("idx")
|
||||
@ -553,7 +553,7 @@ public class HDRPercentileRanksIT extends AbstractNumericTestCase {
|
||||
// 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("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.values(50.0).script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -245,7 +245,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.field("value")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -270,7 +270,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.field("value")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -310,7 +310,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -331,7 +331,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.field("values")
|
||||
.script(new Script("20 - _value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "20 - _value", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -356,7 +356,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -377,7 +377,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
percentiles("percentiles")
|
||||
.numberOfSignificantValueDigits(sigDigits)
|
||||
.method(PercentilesMethod.HDR)
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -392,7 +392,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
|
||||
|
||||
final double[] pcts = randomPercentiles();
|
||||
int sigDigits = randomSignificantDigits();
|
||||
@ -418,7 +418,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
final double[] pcts = randomPercentiles();
|
||||
int sigDigits = randomSignificantDigits();
|
||||
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client()
|
||||
.prepareSearch("idx")
|
||||
@ -544,7 +544,7 @@ public class HDRPercentilesIT extends AbstractNumericTestCase {
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(percentiles("foo").method(PercentilesMethod.HDR).field("d").percentiles(50.0)
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -165,7 +165,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.field("value")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -185,7 +185,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.field("value")
|
||||
.script(new Script("_value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + inc", params)))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -218,7 +218,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.field("values")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -238,7 +238,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.field("values")
|
||||
.script(new Script("_value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + inc", params)))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -255,7 +255,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -271,7 +271,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("inc", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value + inc", params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -292,7 +292,8 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
max("max")
|
||||
.script(new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, "doc['values'].values", Collections.emptyMap())))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -308,8 +309,8 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("inc", 1);
|
||||
|
||||
Script script = new Script("[ doc['value'].value, doc['value'].value + inc ]", ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, params);
|
||||
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))
|
||||
@ -372,7 +373,7 @@ public class MaxIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
max("foo").field("d").script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
max("foo").field("d").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
min("min")
|
||||
.field("value")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -182,7 +182,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -219,7 +219,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
min("min")
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -237,7 +237,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
min("min")
|
||||
.field("values")
|
||||
.script(new Script("_value * -1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value * -1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -253,7 +253,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(min("min").field("values").script(script))
|
||||
@ -269,7 +269,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
|
||||
@Override
|
||||
public void testScriptSingleValued() throws Exception {
|
||||
Script script = new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(min("min").script(script))
|
||||
@ -288,7 +288,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(min("min").script(script))
|
||||
@ -304,7 +304,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
|
||||
@Override
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(min("min").script(script))
|
||||
.get();
|
||||
@ -385,7 +385,7 @@ public class MinIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
min("foo").field("d").script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
min("foo").field("d").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -277,7 +277,7 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testMap() {
|
||||
Script mapScript = new Script("_agg['count'] = 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg['count'] = 1", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -317,7 +317,7 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("_agg", new ArrayList<>());
|
||||
|
||||
Script mapScript = new Script("_agg.add(1)", ScriptType.INLINE, CustomScriptPlugin.NAME, params);
|
||||
Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", params);
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -365,8 +365,10 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
scriptedMetric("scripted")
|
||||
.params(params)
|
||||
.initScript(new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.mapScript(new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.initScript(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "vars.multiplier = 3", Collections.emptyMap()))
|
||||
.mapScript(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"_agg.add(vars.multiplier)", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(response);
|
||||
assertThat(response.getHits().getTotalHits(), equalTo(numDocs));
|
||||
@ -404,8 +406,9 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script mapScript = new Script("_agg.add(1)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", Collections.emptyMap());
|
||||
Script combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -455,9 +458,10 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -508,10 +512,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", 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")
|
||||
@ -551,10 +557,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", Collections.emptyMap());
|
||||
Script reduceScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum aggs of agg values as a new aggregation", Collections.emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client()
|
||||
.prepareSearch("idx")
|
||||
@ -605,9 +613,11 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(vars.multiplier)", Collections.emptyMap());
|
||||
Script combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", 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")
|
||||
@ -645,9 +655,10 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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")
|
||||
@ -684,8 +695,9 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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")
|
||||
@ -725,11 +737,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
Map<String, Object> reduceParams = new HashMap<>();
|
||||
reduceParams.put("multiplier", 4);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("multiplied sum aggs of agg values as a new aggregation", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, reduceParams);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", Collections.emptyMap());
|
||||
Script reduceScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "multiplied sum aggs of agg values as a new aggregation", reduceParams);
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -774,10 +787,14 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
scriptedMetric("scripted")
|
||||
.params(params)
|
||||
.initScript(new Script("initScript_stored", ScriptType.STORED, CustomScriptPlugin.NAME, null))
|
||||
.mapScript(new Script("mapScript_stored", ScriptType.STORED, CustomScriptPlugin.NAME, null))
|
||||
.combineScript(new Script("combineScript_stored", ScriptType.STORED, CustomScriptPlugin.NAME, null))
|
||||
.reduceScript(new Script("reduceScript_stored", ScriptType.STORED, CustomScriptPlugin.NAME, null)))
|
||||
.initScript(
|
||||
new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "initScript_stored", Collections.emptyMap()))
|
||||
.mapScript(
|
||||
new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "mapScript_stored", Collections.emptyMap()))
|
||||
.combineScript(
|
||||
new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "combineScript_stored", Collections.emptyMap()))
|
||||
.reduceScript(
|
||||
new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "reduceScript_stored", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(response);
|
||||
assertThat(response.getHits().getTotalHits(), equalTo(numDocs));
|
||||
@ -810,10 +827,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
.addAggregation(
|
||||
scriptedMetric("scripted")
|
||||
.params(params)
|
||||
.initScript(new Script("init_script", ScriptType.FILE, CustomScriptPlugin.NAME, null))
|
||||
.mapScript(new Script("map_script", ScriptType.FILE, CustomScriptPlugin.NAME, null))
|
||||
.combineScript(new Script("combine_script", ScriptType.FILE, CustomScriptPlugin.NAME, null))
|
||||
.reduceScript(new Script("reduce_script", ScriptType.FILE, CustomScriptPlugin.NAME, null)))
|
||||
.initScript(new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "init_script", Collections.emptyMap()))
|
||||
.mapScript(new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "map_script", Collections.emptyMap()))
|
||||
.combineScript(
|
||||
new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "combine_script", Collections.emptyMap()))
|
||||
.reduceScript(
|
||||
new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "reduce_script", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(response);
|
||||
assertThat(response.getHits().getTotalHits(), equalTo(numDocs));
|
||||
@ -841,10 +860,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", 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")
|
||||
@ -900,10 +921,12 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
params.put("_agg", new ArrayList<>());
|
||||
params.put("vars", varsMap);
|
||||
|
||||
Script initScript = new Script("vars.multiplier = 3", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script("_agg.add(vars.multiplier)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script combineScript = new Script("sum agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script reduceScript = new Script("sum aggs of agg values as a new aggregation", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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 combineScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum agg values as a new aggregation", Collections.emptyMap());
|
||||
Script reduceScript =
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum aggs of agg values as a new aggregation", Collections.emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -939,7 +962,7 @@ public class ScriptedMetricIT extends ESIntegTestCase {
|
||||
* not using a script does get cached.
|
||||
*/
|
||||
public void testDontCacheScripts() throws Exception {
|
||||
Script mapScript = new Script("_agg['count'] = 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg['count'] = 1", Collections.emptyMap());
|
||||
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());
|
||||
|
@ -24,6 +24,7 @@ import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
|
||||
import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -54,7 +55,8 @@ public class ScriptedMetricTests extends BaseAggregationTestCase<ScriptedMetricA
|
||||
if (randomBoolean()) {
|
||||
return new Script(script);
|
||||
} else {
|
||||
return new Script(script, randomFrom(ScriptType.values()), randomFrom("my_lang", null), null);
|
||||
return new Script(
|
||||
randomFrom(ScriptType.values()), randomFrom("my_lang", Script.DEFAULT_SCRIPT_LANG), script, Collections.emptyMap());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
stats("stats")
|
||||
.field("value")
|
||||
.script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertShardExecutionState(searchResponse, 0);
|
||||
@ -255,7 +255,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
stats("stats")
|
||||
.field("value")
|
||||
.script(new Script("_value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + inc", params)))
|
||||
.get();
|
||||
|
||||
assertShardExecutionState(searchResponse, 0);
|
||||
@ -300,7 +300,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
stats("stats")
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertShardExecutionState(searchResponse, 0);
|
||||
@ -326,7 +326,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
stats("stats")
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params)))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params)))
|
||||
.get();
|
||||
|
||||
assertShardExecutionState(searchResponse, 0);
|
||||
@ -349,7 +349,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
stats("stats")
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap())))
|
||||
.get();
|
||||
|
||||
assertShardExecutionState(searchResponse, 0);
|
||||
@ -371,7 +371,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("inc", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value + inc", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value + inc", params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -394,7 +394,7 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
|
||||
@Override
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -420,8 +420,8 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("[ doc['value'].value, doc['value'].value - dec ]", ScriptType.INLINE,
|
||||
AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "[ doc['value'].value, doc['value'].value - dec ]",
|
||||
params);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -508,7 +508,8 @@ public class StatsIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(
|
||||
stats("foo").field("d").script(new Script("_value + 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, null))).get();
|
||||
stats("foo").field("d").script(
|
||||
new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -44,6 +44,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -175,7 +176,8 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
public void testSingleValuedFieldWithValueScript() throws Exception {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null)))
|
||||
.addAggregation(sum("sum").field("value").script(
|
||||
new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -192,7 +194,7 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
params.put("increment", 1);
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params)))
|
||||
.addAggregation(sum("sum").field("value").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -207,7 +209,8 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
public void testScriptSingleValued() throws Exception {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null)))
|
||||
.addAggregation(sum("sum").script(
|
||||
new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "value", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -224,7 +227,7 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
params.put("inc", 1);
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params)))
|
||||
.addAggregation(sum("sum").script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "value", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -239,7 +242,8 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null)))
|
||||
.addAggregation(sum("sum").script(
|
||||
new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "values", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -257,7 +261,7 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
sum("sum").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params)))
|
||||
sum("sum").script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "values", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -289,7 +293,8 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null)))
|
||||
.addAggregation(sum("sum").field("values").script(
|
||||
new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap())))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -305,7 +310,7 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("increment", 1);
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params)))
|
||||
.addAggregation(sum("sum").field("values").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
@ -365,7 +370,8 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(sum("foo").field("d").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).get();
|
||||
.addAggregation(sum("foo").field("d").script(
|
||||
new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
|
@ -241,7 +241,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.field("value")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -262,7 +262,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.field("value")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -297,7 +297,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -315,7 +315,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.field("values")
|
||||
.script(new Script("_value * -1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value * -1", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -336,7 +336,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -354,7 +354,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
.addAggregation(
|
||||
randomCompression(
|
||||
percentileRanks("percentile_ranks"))
|
||||
.script(new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap()))
|
||||
.values(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -369,7 +369,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
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")
|
||||
@ -390,7 +390,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
@Override
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
final double[] pcts = randomPercents(minValues, maxValues);
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(
|
||||
@ -502,7 +502,7 @@ public class TDigestPercentileRanksIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(percentileRanks("foo").field("d").values(50.0)
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))).get();
|
||||
.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()
|
||||
|
@ -226,7 +226,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentiles("percentiles"))
|
||||
.field("value")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -247,7 +247,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentiles("percentiles"))
|
||||
.field("value")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -280,7 +280,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentiles("percentiles"))
|
||||
.field("values")
|
||||
.script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -298,7 +298,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentiles("percentiles"))
|
||||
.field("values")
|
||||
.script(new Script("_value * -1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap()))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value * -1", emptyMap()))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -319,7 +319,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
randomCompression(
|
||||
percentiles("percentiles"))
|
||||
.field("values")
|
||||
.script(new Script("_value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params))
|
||||
.script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params))
|
||||
.percentiles(pcts))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -331,7 +331,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
|
||||
@Override
|
||||
public void testScriptSingleValued() throws Exception {
|
||||
Script script = new Script("doc['value'].value", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap());
|
||||
final double[] pcts = randomPercentiles();
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -353,7 +353,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("dec", 1);
|
||||
|
||||
Script script = new Script("doc['value'].value - dec", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
|
||||
|
||||
final double[] pcts = randomPercentiles();
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
@ -374,7 +374,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
@Override
|
||||
public void testScriptMultiValued() throws Exception {
|
||||
final double[] pcts = randomPercentiles();
|
||||
Script script = new Script("doc['values'].values", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap());
|
||||
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx")
|
||||
.setQuery(matchAllQuery())
|
||||
@ -488,7 +488,7 @@ public class TDigestPercentilesIT extends AbstractNumericTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(percentiles("foo").field("d")
|
||||
.percentiles(50.0).script(new Script("_value - 1", ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, emptyMap())))
|
||||
.percentiles(50.0).script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -583,7 +583,7 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||
.explain(true)
|
||||
.storedField("text")
|
||||
.fieldDataField("field1")
|
||||
.scriptField("script", new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
||||
.scriptField("script", new Script(ScriptType.INLINE, MockScriptEngine.NAME, "5", Collections.emptyMap()))
|
||||
.fetchSource("text", null)
|
||||
.version(true)
|
||||
)
|
||||
@ -865,7 +865,7 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||
nested("to-comments", "comments").subAggregation(
|
||||
topHits("top-comments").size(1).highlighter(new HighlightBuilder().field(hlField)).explain(true)
|
||||
.fieldDataField("comments.user")
|
||||
.scriptField("script", new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())).fetchSource("comments.message", null)
|
||||
.scriptField("script", new Script(ScriptType.INLINE, MockScriptEngine.NAME, "5", Collections.emptyMap())).fetchSource("comments.message", null)
|
||||
.version(true).sort("comments.date", SortOrder.ASC))).get();
|
||||
assertHitCount(searchResponse, 2);
|
||||
Nested nested = searchResponse.getAggregations().get("to-comments");
|
||||
@ -1014,7 +1014,8 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||
|
||||
// Test that a request using a script field does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(topHits("foo").scriptField("bar", new Script("5", ScriptType.INLINE, CustomScriptPlugin.NAME, null))).get();
|
||||
.addAggregation(topHits("foo").scriptField("bar",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "5", Collections.emptyMap()))).get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
||||
@ -1025,7 +1026,8 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||
// Test that a request using a script sort does not get cached
|
||||
r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(topHits("foo").sort(
|
||||
SortBuilders.scriptSort(new Script("5", ScriptType.INLINE, CustomScriptPlugin.NAME, null), ScriptSortType.STRING)))
|
||||
SortBuilders.scriptSort(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "5", Collections.emptyMap()), ScriptSortType.STRING)))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -157,7 +157,7 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
|
||||
public void testSingleValuedScript() throws Exception {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(count("count").script(new Script("value", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
|
||||
.addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "value", Collections.emptyMap()))).execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
|
||||
@ -169,7 +169,7 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
|
||||
public void testMultiValuedScript() throws Exception {
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(count("count").script(new Script("values", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
|
||||
.addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "values", Collections.emptyMap()))).execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
|
||||
@ -182,7 +182,7 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
public void testSingleValuedScriptWithParams() throws Exception {
|
||||
Map<String, Object> params = Collections.singletonMap("s", "value");
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(count("count").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
|
||||
.addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params))).execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
|
||||
@ -195,7 +195,7 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
public void testMultiValuedScriptWithParams() throws Exception {
|
||||
Map<String, Object> params = Collections.singletonMap("s", "values");
|
||||
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
|
||||
.addAggregation(count("count").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
|
||||
.addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params))).execute().actionGet();
|
||||
|
||||
assertHitCount(searchResponse, 10);
|
||||
|
||||
@ -224,7 +224,8 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
|
||||
// Test that a request using a script does not get cached
|
||||
SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
|
||||
.addAggregation(count("foo").field("d").script(new Script("value", ScriptType.INLINE, FieldValueScriptEngine.NAME, null)))
|
||||
.addAggregation(count("foo").field("d").script(
|
||||
new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "value", Collections.emptyMap())))
|
||||
.get();
|
||||
assertSearchResponse(r);
|
||||
|
||||
|
@ -164,8 +164,9 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null)
|
||||
, "field2Sum", "field3Sum", "field4Sum")))
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -210,7 +211,8 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 / _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "_value0 + _value1 / _value2", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -256,7 +258,7 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null)
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap())
|
||||
, "field2Sum", "field3Sum", "field4Sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -300,7 +302,7 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field2Sum").field(FIELD_2_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0", ScriptType.INLINE, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value0", Collections.emptyMap()),
|
||||
"field2Sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -344,7 +346,8 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic", bucketsPathsMap,
|
||||
new Script("foo + bar + baz", ScriptType.INLINE, CustomScriptPlugin.NAME, null))))
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "foo + bar + baz", Collections.emptyMap()))))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -381,7 +384,7 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("factor", 3);
|
||||
|
||||
Script script = new Script("(_value0 + _value1 + _value2) * factor", ScriptType.INLINE, CustomScriptPlugin.NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "(_value0 + _value1 + _value2) * factor", params);
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -437,7 +440,8 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum").gapPolicy(GapPolicy.INSERT_ZEROS)))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -491,7 +495,7 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("my_script", ScriptType.STORED, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "my_script", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum"))).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
@ -536,7 +540,8 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
@ -560,7 +565,8 @@ public class BucketScriptIT extends ESIntegTestCase {
|
||||
.subAggregation(sum("field4Sum").field(FIELD_4_NAME))
|
||||
.subAggregation(
|
||||
bucketScript("seriesArithmetic",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, CustomScriptPlugin.NAME, null),
|
||||
new Script(ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
|
||||
"field2Sum", "field3Sum", "field4Sum"))).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -42,12 +42,11 @@ public class BucketScriptTests extends BasePipelineAggregationTestCase<BucketScr
|
||||
if (randomBoolean()) {
|
||||
script = new Script("script");
|
||||
} else {
|
||||
Map<String, Object> params = null;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (randomBoolean()) {
|
||||
params = new HashMap<String, Object>();
|
||||
params.put("foo", "bar");
|
||||
}
|
||||
script = new Script("script", randomFrom(ScriptType.values()), randomFrom("my_lang", null), params);
|
||||
script = new Script(randomFrom(ScriptType.values()), randomFrom("my_lang", Script.DEFAULT_SCRIPT_LANG), "script", params);
|
||||
}
|
||||
BucketScriptPipelineAggregationBuilder factory = new BucketScriptPipelineAggregationBuilder(name, bucketsPaths, script);
|
||||
if (randomBoolean()) {
|
||||
|
@ -176,8 +176,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScript() {
|
||||
Script script =
|
||||
new Script("Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field(FIELD_1_NAME).interval(interval)
|
||||
@ -205,7 +205,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptNoBucketsPruned() {
|
||||
Script script = new Script("Double.isNaN(_value0) ? true : (_value0 < 10000)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? true : (_value0 < 10000)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -238,7 +239,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptNoBucketsLeft() {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 > 10000)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 > 10000)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -261,7 +263,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScript2() {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 < _value1)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 < _value1)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -294,7 +297,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptSingleVariable() {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 > 100)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 > 100)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -323,8 +327,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptNamedVars() {
|
||||
Script script = new Script("Double.isNaN(my_value1) ? false : (my_value1 + my_value2 > 100)", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null);
|
||||
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");
|
||||
@ -360,8 +364,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptWithParams() {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 + _value1 > threshold)", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, Collections.singletonMap("threshold", 100));
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 + _value1 > threshold)", Collections.singletonMap("threshold", 100));
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(
|
||||
@ -393,7 +397,7 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testInlineScriptInsertZeros() {
|
||||
Script script = new Script("_value0 + _value1 > 100", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value0 + _value1 > 100", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(
|
||||
@ -432,7 +436,7 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
// Source is not interpreted but my_script is defined in CustomScriptPlugin
|
||||
.setSource(new BytesArray("{ \"script\": \"Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)\" }")));
|
||||
|
||||
Script script = new Script("my_script", ScriptType.STORED, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.STORED, CustomScriptPlugin.NAME, "my_script", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client()
|
||||
.prepareSearch("idx")
|
||||
@ -465,8 +469,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testUnmapped() throws Exception {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
|
||||
"Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(
|
||||
@ -487,8 +491,8 @@ public class BucketSelectorIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testPartiallyUnmapped() throws Exception {
|
||||
Script script = new Script("Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null);
|
||||
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(
|
||||
|
@ -42,12 +42,11 @@ public class BucketSelectorTests extends BasePipelineAggregationTestCase<BucketS
|
||||
if (randomBoolean()) {
|
||||
script = new Script("script");
|
||||
} else {
|
||||
Map<String, Object> params = null;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (randomBoolean()) {
|
||||
params = new HashMap<String, Object>();
|
||||
params.put("foo", "bar");
|
||||
}
|
||||
script = new Script("script", randomFrom(ScriptType.values()), randomFrom("my_lang", null), params);
|
||||
script = new Script(randomFrom(ScriptType.values()), randomFrom("my_lang", Script.DEFAULT_SCRIPT_LANG), "script", params);
|
||||
}
|
||||
BucketSelectorPipelineAggregationBuilder factory = new BucketSelectorPipelineAggregationBuilder(name, bucketsPaths, script);
|
||||
if (randomBoolean()) {
|
||||
|
@ -43,6 +43,7 @@ import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@ -450,7 +451,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase {
|
||||
|
||||
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("foo", ScriptType.INLINE, "bar", null)))))
|
||||
.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();
|
||||
|
@ -167,7 +167,7 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
.setExplain(true)
|
||||
.addDocValueField("comments.message")
|
||||
.addScriptField("script",
|
||||
new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
||||
new Script(ScriptType.INLINE, MockScriptEngine.NAME, "5", Collections.emptyMap()))
|
||||
.setSize(1)
|
||||
)).get();
|
||||
assertNoFailures(response);
|
||||
@ -301,8 +301,8 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
.addDocValueField("message")
|
||||
.setHighlightBuilder(new HighlightBuilder().field("message"))
|
||||
.setExplain(true).setSize(1)
|
||||
.addScriptField("script", new Script("5", ScriptType.INLINE,
|
||||
MockScriptEngine.NAME, Collections.emptyMap()))
|
||||
.addScriptField("script", new Script(ScriptType.INLINE, MockScriptEngine.NAME, "5",
|
||||
Collections.emptyMap()))
|
||||
)
|
||||
).get();
|
||||
assertNoFailures(response);
|
||||
|
@ -285,9 +285,12 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.addScriptField("sNum1", new Script("doc['num1'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("sNum1_field", new Script("_fields['num1'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("date1", new Script("doc['date'].date.millis", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("sNum1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
|
||||
.addScriptField("sNum1_field",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields['num1'].value", Collections.emptyMap()))
|
||||
.addScriptField("date1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['date'].date.millis", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -321,7 +324,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
response = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.addScriptField("sNum1", new Script("doc['num1'].value * factor", ScriptType.INLINE, CustomScriptPlugin.NAME, params))
|
||||
.addScriptField("sNum1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value * factor", params))
|
||||
.get();
|
||||
|
||||
assertThat(response.getHits().totalHits(), equalTo(3L));
|
||||
@ -357,7 +360,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.setSize(numDocs)
|
||||
.addScriptField("uid", new Script("_fields._uid.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("uid", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._uid.value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -375,7 +378,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.setSize(numDocs)
|
||||
.addScriptField("id", new Script("_fields._id.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("id", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._id.value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -393,7 +396,8 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.setSize(numDocs)
|
||||
.addScriptField("type", new Script("_fields._type.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("type",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._type.value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -411,9 +415,10 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.setSize(numDocs)
|
||||
.addScriptField("id", new Script("_fields._id.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("uid", new Script("_fields._uid.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("type", new Script("_fields._type.value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("id", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._id.value", Collections.emptyMap()))
|
||||
.addScriptField("uid", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._uid.value", Collections.emptyMap()))
|
||||
.addScriptField("type",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_fields._type.value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -444,11 +449,13 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
|
||||
SearchResponse response = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("s_obj1", new Script("_source.obj1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("s_obj1_test", new Script("_source.obj1.test", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("s_obj2", new Script("_source.obj2", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("s_obj2_arr2", new Script("_source.obj2.arr2", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("s_arr3", new Script("_source.arr3", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("s_obj1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.obj1", Collections.emptyMap()))
|
||||
.addScriptField("s_obj1_test",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.obj1.test", Collections.emptyMap()))
|
||||
.addScriptField("s_obj2", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.obj2", Collections.emptyMap()))
|
||||
.addScriptField("s_obj2_arr2",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.obj2.arr2", Collections.emptyMap()))
|
||||
.addScriptField("s_arr3", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.arr3", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||
@ -481,7 +488,8 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
|
||||
SearchResponse response = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("test_script_1", new Script("return null", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("test_script_1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "return null", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertNoFailures(response);
|
||||
@ -847,7 +855,8 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
||||
ensureSearchable();
|
||||
SearchRequestBuilder req = client().prepareSearch("index");
|
||||
for (String field : Arrays.asList("s", "ms", "l", "ml", "d", "md")) {
|
||||
req.addScriptField(field, new Script("doc['" + field + "'].values", ScriptType.INLINE, CustomScriptPlugin.NAME, null));
|
||||
req.addScriptField(field,
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + field + "'].values", Collections.emptyMap()));
|
||||
}
|
||||
SearchResponse resp = req.get();
|
||||
assertSearchResponse(resp);
|
||||
|
@ -44,6 +44,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -76,7 +77,8 @@ public class ExplainableScriptIT extends ESIntegTestCase {
|
||||
SearchResponse response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
|
||||
searchSource().explain(true).query(
|
||||
functionScoreQuery(termQuery("text", "text"),
|
||||
scriptFunction(new Script("native_explainable_script", ScriptType.INLINE, "native", null)))
|
||||
scriptFunction(
|
||||
new Script(ScriptType.INLINE, "native", "native_explainable_script", Collections.emptyMap())))
|
||||
.boostMode(CombineFunction.REPLACE)))).actionGet();
|
||||
|
||||
ElasticsearchAssertions.assertNoFailures(response);
|
||||
|
@ -94,8 +94,8 @@ public class FunctionScoreIT extends ESIntegTestCase {
|
||||
index(INDEX, TYPE, "1", jsonBuilder().startObject().field("dummy_field", 1).endObject());
|
||||
refresh();
|
||||
|
||||
Script scriptOne = new Script("1", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script scriptTwo = new Script("get score value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script scriptOne = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "1", Collections.emptyMap());
|
||||
Script scriptTwo = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get score value", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().search(
|
||||
searchRequest().source(
|
||||
@ -118,7 +118,7 @@ public class FunctionScoreIT extends ESIntegTestCase {
|
||||
index(INDEX, TYPE, "1", jsonBuilder().startObject().field("dummy_field", 1).endObject());
|
||||
refresh();
|
||||
|
||||
Script script = new Script("get score value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get score value", Collections.emptyMap());
|
||||
|
||||
SearchResponse response = client().search(
|
||||
searchRequest().source(
|
||||
@ -146,7 +146,7 @@ public class FunctionScoreIT extends ESIntegTestCase {
|
||||
refresh();
|
||||
ensureYellow();
|
||||
|
||||
Script script = new Script("doc['random_score']", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
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();
|
||||
@ -178,7 +178,7 @@ public class FunctionScoreIT extends ESIntegTestCase {
|
||||
docs.add(client().prepareIndex(INDEX, TYPE, Integer.toString(i)).setSource("num", i + scoreOffset));
|
||||
}
|
||||
indexRandom(true, docs);
|
||||
Script script = new Script("return (doc['num'].value)", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "return (doc['num'].value)", Collections.emptyMap());
|
||||
int numMatchingDocs = numDocs + scoreOffset - minScore;
|
||||
if (numMatchingDocs < 0) {
|
||||
numMatchingDocs = 0;
|
||||
|
@ -169,7 +169,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase {
|
||||
params.put("factor", randomIntBetween(2, 4));
|
||||
|
||||
// Test for accessing _score
|
||||
Script script = new Script("log(doc['index'].value + (factor * _score))", ScriptType.INLINE, NAME, params);
|
||||
Script script = new Script(ScriptType.INLINE, NAME, "log(doc['index'].value + (factor * _score))", params);
|
||||
SearchResponse resp = client()
|
||||
.prepareSearch("test")
|
||||
.setQuery(
|
||||
@ -185,7 +185,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase {
|
||||
assertThat(firstHit.getScore(), greaterThan(1f));
|
||||
|
||||
// Test for accessing _score.intValue()
|
||||
script = new Script("log(doc['index'].value + (factor * _score.intValue()))", ScriptType.INLINE, NAME, params);
|
||||
script = new Script(ScriptType.INLINE, NAME, "log(doc['index'].value + (factor * _score.intValue()))", params);
|
||||
resp = client()
|
||||
.prepareSearch("test")
|
||||
.setQuery(
|
||||
@ -201,7 +201,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase {
|
||||
assertThat(firstHit.getScore(), greaterThan(1f));
|
||||
|
||||
// Test for accessing _score.longValue()
|
||||
script = new Script("log(doc['index'].value + (factor * _score.longValue()))", ScriptType.INLINE, NAME, params);
|
||||
script = new Script(ScriptType.INLINE, NAME, "log(doc['index'].value + (factor * _score.longValue()))", params);
|
||||
resp = client()
|
||||
.prepareSearch("test")
|
||||
.setQuery(
|
||||
@ -217,7 +217,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase {
|
||||
assertThat(firstHit.getScore(), greaterThan(1f));
|
||||
|
||||
// Test for accessing _score.floatValue()
|
||||
script = new Script("log(doc['index'].value + (factor * _score.floatValue()))", ScriptType.INLINE, NAME, params);
|
||||
script = new Script(ScriptType.INLINE, NAME, "log(doc['index'].value + (factor * _score.floatValue()))", params);
|
||||
resp = client()
|
||||
.prepareSearch("test")
|
||||
.setQuery(
|
||||
@ -233,7 +233,7 @@ public class RandomScoreFunctionIT extends ESIntegTestCase {
|
||||
assertThat(firstHit.getScore(), greaterThan(1f));
|
||||
|
||||
// Test for accessing _score.doubleValue()
|
||||
script = new Script("log(doc['index'].value + (factor * _score.doubleValue()))", ScriptType.INLINE, NAME, params);
|
||||
script = new Script(ScriptType.INLINE, NAME, "log(doc['index'].value + (factor * _score.doubleValue()))", params);
|
||||
resp = client()
|
||||
.prepareSearch("test")
|
||||
.setQuery(
|
||||
|
@ -48,6 +48,7 @@ import org.junit.Before;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -127,7 +128,7 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||
|
||||
// Test doc['location'].arcDistance(lat, lon)
|
||||
SearchResponse searchResponse1 = client().prepareSearch().addStoredField("_source")
|
||||
.addScriptField("distance", new Script("arcDistance", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("distance", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "arcDistance", Collections.emptyMap()))
|
||||
.get();
|
||||
Double resultDistance1 = searchResponse1.getHits().getHits()[0].getFields().get("distance").getValue();
|
||||
assertThat(resultDistance1,
|
||||
@ -135,16 +136,16 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||
|
||||
// Test doc['location'].planeDistance(lat, lon)
|
||||
SearchResponse searchResponse2 = client().prepareSearch().addStoredField("_source")
|
||||
.addScriptField("distance", new Script("planeDistance", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)).get();
|
||||
.addScriptField("distance", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "planeDistance",
|
||||
Collections.emptyMap())).get();
|
||||
Double resultDistance2 = searchResponse2.getHits().getHits()[0].getFields().get("distance").getValue();
|
||||
assertThat(resultDistance2,
|
||||
closeTo(GeoUtils.planeDistance(src_lat, src_lon, tgt_lat, tgt_lon), 0.01d));
|
||||
|
||||
// Test doc['location'].geohashDistance(lat, lon)
|
||||
SearchResponse searchResponse4 = client().prepareSearch().addStoredField("_source")
|
||||
.addScriptField("distance", new Script("geohashDistance", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)).get();
|
||||
.addScriptField("distance", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "geohashDistance",
|
||||
Collections.emptyMap())).get();
|
||||
Double resultDistance4 = searchResponse4.getHits().getHits()[0].getFields().get("distance").getValue();
|
||||
assertThat(resultDistance4,
|
||||
closeTo(GeoUtils.arcDistance(src_lat, src_lon, GeoHashUtils.decodeLatitude(tgt_geohash),
|
||||
@ -152,16 +153,16 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||
|
||||
// Test doc['location'].arcDistance(lat, lon + 360)/1000d
|
||||
SearchResponse searchResponse5 = client().prepareSearch().addStoredField("_source")
|
||||
.addScriptField("distance", new Script("arcDistance(lat, lon + 360)/1000d", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)).get();
|
||||
.addScriptField("distance", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "arcDistance(lat, lon + 360)/1000d",
|
||||
Collections.emptyMap())).get();
|
||||
Double resultArcDistance5 = searchResponse5.getHits().getHits()[0].getFields().get("distance").getValue();
|
||||
assertThat(resultArcDistance5,
|
||||
closeTo(GeoUtils.arcDistance(src_lat, src_lon, tgt_lat, tgt_lon)/1000d, 0.01d));
|
||||
|
||||
// Test doc['location'].arcDistance(lat + 360, lon)/1000d
|
||||
SearchResponse searchResponse6 = client().prepareSearch().addStoredField("_source")
|
||||
.addScriptField("distance", new Script("arcDistance(lat + 360, lon)/1000d", ScriptType.INLINE,
|
||||
CustomScriptPlugin.NAME, null)).get();
|
||||
.addScriptField("distance", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "arcDistance(lat + 360, lon)/1000d",
|
||||
Collections.emptyMap())).get();
|
||||
Double resultArcDistance6 = searchResponse6.getHits().getHits()[0].getFields().get("distance").getValue();
|
||||
assertThat(resultArcDistance6,
|
||||
closeTo(GeoUtils.arcDistance(src_lat, src_lon, tgt_lat, tgt_lon)/1000d, 0.01d));
|
||||
|
@ -104,9 +104,11 @@ public class ScriptQuerySearchIT extends ESIntegTestCase {
|
||||
|
||||
logger.info("running doc['num1'].value > 1");
|
||||
SearchResponse response = client().prepareSearch()
|
||||
.setQuery(scriptQuery(new Script("doc['num1'].value > 1", ScriptType.INLINE, CustomScriptPlugin.NAME, null)))
|
||||
.setQuery(scriptQuery(
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > 1", Collections.emptyMap())))
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.addScriptField("sNum1", new Script("doc['num1'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("sNum1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertThat(response.getHits().totalHits(), equalTo(2L));
|
||||
@ -121,9 +123,10 @@ public class ScriptQuerySearchIT extends ESIntegTestCase {
|
||||
logger.info("running doc['num1'].value > param1");
|
||||
response = client()
|
||||
.prepareSearch()
|
||||
.setQuery(scriptQuery(new Script("doc['num1'].value > param1", ScriptType.INLINE, CustomScriptPlugin.NAME, params)))
|
||||
.setQuery(scriptQuery(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > param1", params)))
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.addScriptField("sNum1", new Script("doc['num1'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("sNum1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertThat(response.getHits().totalHits(), equalTo(1L));
|
||||
@ -135,9 +138,10 @@ public class ScriptQuerySearchIT extends ESIntegTestCase {
|
||||
logger.info("running doc['num1'].value > param1");
|
||||
response = client()
|
||||
.prepareSearch()
|
||||
.setQuery(scriptQuery(new Script("doc['num1'].value > param1", ScriptType.INLINE, CustomScriptPlugin.NAME, params)))
|
||||
.setQuery(scriptQuery(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > param1", params)))
|
||||
.addSort("num1", SortOrder.ASC)
|
||||
.addScriptField("sNum1", new Script("doc['num1'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("sNum1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
|
||||
.get();
|
||||
|
||||
assertThat(response.getHits().totalHits(), equalTo(3L));
|
||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.sort.ScriptSortBuilder.ScriptSortType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -76,7 +77,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
||||
Script script = original.script();
|
||||
ScriptSortType type = original.type();
|
||||
if (randomBoolean()) {
|
||||
result = new ScriptSortBuilder(new Script(script.getScript() + "_suffix"), type);
|
||||
result = new ScriptSortBuilder(new Script(script.getIdOrCode() + "_suffix"), type);
|
||||
} else {
|
||||
result = new ScriptSortBuilder(script, type.equals(ScriptSortType.NUMBER) ? ScriptSortType.STRING : ScriptSortType.NUMBER);
|
||||
}
|
||||
@ -173,7 +174,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
ScriptSortBuilder builder = ScriptSortBuilder.fromXContent(context, null);
|
||||
assertEquals("doc['field_name'].value * factor", builder.script().getScript());
|
||||
assertEquals("doc['field_name'].value * factor", builder.script().getIdOrCode());
|
||||
assertEquals(Script.DEFAULT_SCRIPT_LANG, builder.script().getLang());
|
||||
assertEquals(1.1, builder.script().getParams().get("factor"));
|
||||
assertEquals(ScriptType.INLINE, builder.script().getType());
|
||||
@ -199,9 +200,9 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
ScriptSortBuilder builder = ScriptSortBuilder.fromXContent(context, null);
|
||||
assertEquals("doc['field_name'].value", builder.script().getScript());
|
||||
assertEquals("doc['field_name'].value", builder.script().getIdOrCode());
|
||||
assertEquals(Script.DEFAULT_SCRIPT_LANG, builder.script().getLang());
|
||||
assertNull(builder.script().getParams());
|
||||
assertEquals(builder.script().getParams(), Collections.emptyMap());
|
||||
assertEquals(ScriptType.INLINE, builder.script().getType());
|
||||
assertEquals(ScriptSortType.NUMBER, builder.type());
|
||||
assertEquals(SortOrder.ASC, builder.order());
|
||||
|
@ -183,7 +183,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
// STRING script
|
||||
int size = 1 + random.nextInt(10);
|
||||
|
||||
Script script = new Script("doc['str_value'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['str_value'].value", Collections.emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
@ -275,7 +275,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
// test the long values
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("min", new Script("get min long", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("min", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get min long", Collections.emptyMap()))
|
||||
.addSort(SortBuilders.fieldSort("ord").order(SortOrder.ASC).unmappedType("long"))
|
||||
.setSize(10)
|
||||
.get();
|
||||
@ -291,7 +291,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
// test the double values
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("min", new Script("get min double", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("min", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get min double", Collections.emptyMap()))
|
||||
.addSort(SortBuilders.fieldSort("ord").order(SortOrder.ASC).unmappedType("long"))
|
||||
.setSize(10)
|
||||
.get();
|
||||
@ -307,7 +307,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
// test the string values
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("min", new Script("get min string", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("min", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get min string", Collections.emptyMap()))
|
||||
.addSort(SortBuilders.fieldSort("ord").order(SortOrder.ASC).unmappedType("long"))
|
||||
.setSize(10)
|
||||
.get();
|
||||
@ -323,7 +323,8 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
// test the geopoint values
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("min", new Script("get min geopoint lon", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("min",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "get min geopoint lon", Collections.emptyMap()))
|
||||
.addSort(SortBuilders.fieldSort("ord").order(SortOrder.ASC).unmappedType("long"))
|
||||
.setSize(10)
|
||||
.get();
|
||||
@ -381,7 +382,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
flush();
|
||||
refresh();
|
||||
|
||||
Script scripField = new Script("doc['id'].value", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script scripField = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['id'].value", Collections.emptyMap());
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
@ -398,7 +399,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addScriptField("id", new Script("doc['id'].values[0]", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("id", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['id'].values[0]", Collections.emptyMap()))
|
||||
.addSort("svalue", SortOrder.ASC)
|
||||
.get();
|
||||
|
||||
@ -466,7 +467,7 @@ public class SimpleSortIT extends ESIntegTestCase {
|
||||
}
|
||||
refresh();
|
||||
|
||||
Script sortScript = new Script("\u0027\u0027", ScriptType.INLINE, CustomScriptPlugin.NAME, null);
|
||||
Script sortScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "\u0027\u0027", Collections.emptyMap());
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort(scriptSort(sortScript, ScriptSortType.STRING))
|
||||
|
@ -121,7 +121,8 @@ public class SearchStatsIT extends ESIntegTestCase {
|
||||
SearchResponse searchResponse = internalCluster().coordOnlyNodeClient().prepareSearch()
|
||||
.setQuery(QueryBuilders.termQuery("field", "value")).setStats("group1", "group2")
|
||||
.highlighter(new HighlightBuilder().field("field"))
|
||||
.addScriptField("script1", new Script("_source.field", ScriptType.INLINE, CustomScriptPlugin.NAME, null))
|
||||
.addScriptField("script1",
|
||||
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.field", Collections.emptyMap()))
|
||||
.setSize(100)
|
||||
.execute().actionGet();
|
||||
assertHitCount(searchResponse, docsTest1 + docsTest2);
|
||||
|
@ -111,7 +111,7 @@ public class PhraseSuggestionBuilderTests extends AbstractSuggestionBuilderTestC
|
||||
case 6:
|
||||
Script collateQuery = builder.collateQuery();
|
||||
if (collateQuery != null) {
|
||||
builder.collateQuery(randomValueOtherThan(collateQuery.getScript(), () -> randomAsciiOfLengthBetween(3, 20)));
|
||||
builder.collateQuery(randomValueOtherThan(collateQuery.getIdOrCode(), () -> randomAsciiOfLengthBetween(3, 20)));
|
||||
} else {
|
||||
builder.collateQuery(randomAsciiOfLengthBetween(3, 20));
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase {
|
||||
|
||||
try {
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap())).execute().actionGet();
|
||||
fail();
|
||||
} catch (DocumentMissingException e) {
|
||||
// all is well
|
||||
@ -127,15 +127,15 @@ public class TimestampTTLBWIT extends ESIntegTestCase {
|
||||
long ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue();
|
||||
assertThat(ttl, greaterThan(0L));
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "2")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap())).execute().actionGet();
|
||||
getResponse = client().prepareGet("test", "type1", "2").setStoredFields("_ttl").execute().actionGet();
|
||||
ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue();
|
||||
assertThat(ttl, greaterThan(0L));
|
||||
|
||||
// check TTL update
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "2")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values",
|
||||
Collections.singletonMap("_ctx", Collections.singletonMap("_ttl", 3600000)))).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "",
|
||||
Collections.singletonMap("_ctx", Collections.singletonMap("_ttl", 3600000)))).execute().actionGet();
|
||||
getResponse = client().prepareGet("test", "type1", "2").setStoredFields("_ttl").execute().actionGet();
|
||||
ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue();
|
||||
assertThat(ttl, greaterThan(0L));
|
||||
@ -144,8 +144,8 @@ public class TimestampTTLBWIT extends ESIntegTestCase {
|
||||
// check timestamp update
|
||||
client().prepareIndex("test", "type1", "3").setSource("field", 1).setRefreshPolicy(IMMEDIATE).get();
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "3")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values",
|
||||
Collections.singletonMap("_ctx", Collections.singletonMap("_timestamp", "2009-11-15T14:12:12")))).execute()
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "",
|
||||
Collections.singletonMap("_ctx", Collections.singletonMap("_timestamp", "2009-11-15T14:12:12")))).execute()
|
||||
.actionGet();
|
||||
getResponse = client().prepareGet("test", "type1", "3").setStoredFields("_timestamp").execute().actionGet();
|
||||
long timestamp = ((Number) getResponse.getField("_timestamp").getValue()).longValue();
|
||||
@ -198,7 +198,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase {
|
||||
// Update the first object and note context variables values
|
||||
UpdateResponse updateResponse = client().prepareUpdate("test", "subtype1", "id1")
|
||||
.setRouting("routing1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "extract_ctx", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "extract_ctx", "", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
|
||||
assertEquals(2, updateResponse.getVersion());
|
||||
@ -215,7 +215,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase {
|
||||
|
||||
// Idem with the second object
|
||||
updateResponse = client().prepareUpdate("test", "type1", "parentId1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "extract_ctx", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "extract_ctx", "", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
|
||||
assertEquals(2, updateResponse.getVersion());
|
||||
|
@ -57,7 +57,7 @@ public class UpdateByNativeScriptIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("foo", "SETVALUE");
|
||||
client().prepareUpdate("test", "type", "1")
|
||||
.setScript(new Script("custom", ScriptType.INLINE, NativeScriptEngineService.NAME, params)).get();
|
||||
.setScript(new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "custom", params)).get();
|
||||
|
||||
Map<String, Object> data = client().prepareGet("test", "type", "1").get().getSource();
|
||||
assertThat(data, hasKey("foo"));
|
||||
|
@ -369,7 +369,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -381,7 +381,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -410,7 +410,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("balance", openingBalance).endObject())
|
||||
.setScriptedUpsert(true)
|
||||
.setScript(new Script("", ScriptType.INLINE, "scripted_upsert", params))
|
||||
.setScript(new Script(ScriptType.INLINE, "scripted_upsert", "", params))
|
||||
.execute().actionGet();
|
||||
assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -424,7 +424,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("balance", openingBalance).endObject())
|
||||
.setScriptedUpsert(true)
|
||||
.setScript(new Script("", ScriptType.INLINE, "scripted_upsert", params))
|
||||
.setScript(new Script(ScriptType.INLINE, "scripted_upsert", "", params))
|
||||
.execute().actionGet();
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -468,7 +468,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo")))
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
|
||||
.setFetchSource(true)
|
||||
.execute().actionGet();
|
||||
|
||||
@ -480,7 +480,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo")))
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
|
||||
.setFields("_source")
|
||||
.execute().actionGet();
|
||||
|
||||
@ -498,24 +498,24 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
index("test", "type", "1", "text", "value"); // version is now 1
|
||||
|
||||
assertThrows(client().prepareUpdate(indexOrAlias(), "type", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2)
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2"))).setVersion(2)
|
||||
.execute(),
|
||||
VersionConflictEngineException.class);
|
||||
|
||||
client().prepareUpdate(indexOrAlias(), "type", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(1).get();
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2"))).setVersion(1).get();
|
||||
assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(2L));
|
||||
|
||||
// and again with a higher version..
|
||||
client().prepareUpdate(indexOrAlias(), "type", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v3"))).setVersion(2).get();
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v3"))).setVersion(2).get();
|
||||
|
||||
assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(3L));
|
||||
|
||||
// after delete
|
||||
client().prepareDelete("test", "type", "1").get();
|
||||
assertThrows(client().prepareUpdate("test", "type", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(3)
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2"))).setVersion(3)
|
||||
.execute(),
|
||||
DocumentMissingException.class);
|
||||
|
||||
@ -523,7 +523,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "type", "2").setSource("text", "value").setVersion(10).setVersionType(VersionType.EXTERNAL).get();
|
||||
|
||||
assertThrows(client().prepareUpdate(indexOrAlias(), "type", "2")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2)
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2"))).setVersion(2)
|
||||
.setVersionType(VersionType.EXTERNAL).execute(),
|
||||
ActionRequestValidationException.class);
|
||||
|
||||
@ -535,7 +535,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
// With internal versions, tt means "if object is there with version X, update it or explode. If it is not there, index.
|
||||
client().prepareUpdate(indexOrAlias(), "type", "3")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2")))
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("text", "v2")))
|
||||
.setVersion(10).setUpsert("{ \"text\": \"v0\" }").get();
|
||||
get = get("test", "type", "3");
|
||||
assertThat(get.getVersion(), equalTo(1L));
|
||||
@ -548,7 +548,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
public void testIndexAutoCreation() throws Exception {
|
||||
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo")))
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
|
||||
.setFetchSource(true)
|
||||
.execute().actionGet();
|
||||
|
||||
@ -565,7 +565,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
try {
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap())).execute().actionGet();
|
||||
fail();
|
||||
} catch (DocumentMissingException e) {
|
||||
// all is well
|
||||
@ -574,7 +574,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet();
|
||||
|
||||
UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap())).execute().actionGet();
|
||||
assertThat(updateResponse.getVersion(), equalTo(2L));
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -587,7 +587,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("inc", 3);
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", params)).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", params)).execute().actionGet();
|
||||
assertThat(updateResponse.getVersion(), equalTo(3L));
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -599,7 +599,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
// check noop
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "none")))).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("_ctx", Collections.singletonMap("op", "none")))).execute().actionGet();
|
||||
assertThat(updateResponse.getVersion(), equalTo(3L));
|
||||
assertEquals(DocWriteResponse.Result.NOOP, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -611,7 +611,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
// check delete
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "delete")))).execute().actionGet();
|
||||
.setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("_ctx", Collections.singletonMap("op", "delete")))).execute().actionGet();
|
||||
assertThat(updateResponse.getVersion(), equalTo(4L));
|
||||
assertEquals(DocWriteResponse.Result.DELETED, updateResponse.getResult());
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -624,7 +624,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
// check fields parameter
|
||||
client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet();
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setFields("field")
|
||||
.setFetchSource(true)
|
||||
.execute().actionGet();
|
||||
@ -637,7 +637,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
// check _source parameter
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", 1, "field2", 2).execute().actionGet();
|
||||
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field1", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field1", Collections.emptyMap()))
|
||||
.setFetchSource("field1", "field2")
|
||||
.get();
|
||||
assertThat(updateResponse.getIndex(), equalTo("test"));
|
||||
@ -700,7 +700,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
try {
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
fail("Should have thrown ActionRequestValidationException");
|
||||
} catch (ActionRequestValidationException e) {
|
||||
@ -715,7 +715,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
ensureGreen();
|
||||
try {
|
||||
client().prepareUpdate(indexOrAlias(), "type1", "1")
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setDocAsUpsert(true)
|
||||
.execute().actionGet();
|
||||
fail("Should have thrown ActionRequestValidationException");
|
||||
@ -767,7 +767,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
// Update the first object and note context variables values
|
||||
UpdateResponse updateResponse = client().prepareUpdate("test", "subtype1", "id1")
|
||||
.setRouting("routing1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "extract_ctx", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "extract_ctx", "", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
|
||||
assertEquals(2, updateResponse.getVersion());
|
||||
@ -783,7 +783,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
|
||||
// Idem with the second object
|
||||
updateResponse = client().prepareUpdate("test", "type1", "parentId1")
|
||||
.setScript(new Script("", ScriptType.INLINE, "extract_ctx", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "extract_ctx", "", Collections.emptyMap()))
|
||||
.execute().actionGet();
|
||||
|
||||
assertEquals(2, updateResponse.getVersion());
|
||||
@ -822,13 +822,13 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
}
|
||||
if (useBulkApi) {
|
||||
UpdateRequestBuilder updateRequestBuilder = client().prepareUpdate(indexOrAlias(), "type1", Integer.toString(i))
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setRetryOnConflict(Integer.MAX_VALUE)
|
||||
.setUpsert(jsonBuilder().startObject().field("field", 1).endObject());
|
||||
client().prepareBulk().add(updateRequestBuilder).execute().actionGet();
|
||||
} else {
|
||||
client().prepareUpdate(indexOrAlias(), "type1", Integer.toString(i))
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setRetryOnConflict(Integer.MAX_VALUE)
|
||||
.setUpsert(jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.execute().actionGet();
|
||||
@ -948,7 +948,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
updateRequestsOutstanding.acquire();
|
||||
try {
|
||||
UpdateRequest ur = client().prepareUpdate("test", "type1", Integer.toString(j))
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setRetryOnConflict(retryOnConflict)
|
||||
.setUpsert(jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.request();
|
||||
@ -1048,7 +1048,7 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
//All the previous operations should be complete or failed at this point
|
||||
for (int i = 0; i < numberOfIdsPerThread; ++i) {
|
||||
UpdateResponse ur = client().prepareUpdate("test", "type1", Integer.toString(i))
|
||||
.setScript(new Script("field", ScriptType.INLINE, "field_inc", null))
|
||||
.setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap()))
|
||||
.setRetryOnConflict(Integer.MAX_VALUE)
|
||||
.setUpsert(jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.execute().actionGet();
|
||||
|
@ -24,7 +24,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilder.CommonFields;
|
||||
|
||||
@ -111,7 +111,7 @@ public abstract class MultiValuesSourceParser<VS extends ValuesSource> implement
|
||||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
|
||||
parseMissingAndAdd(aggregationName, currentFieldName, parser, missingMap);
|
||||
}
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
} else if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " +
|
||||
"Multi-field aggregations do not support scripts.");
|
||||
@ -121,7 +121,7 @@ public abstract class MultiValuesSourceParser<VS extends ValuesSource> implement
|
||||
"Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "].");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, Script.SCRIPT_PARSE_FIELD)) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " +
|
||||
"Multi-field aggregations do not support scripts.");
|
||||
|
@ -59,7 +59,7 @@ public final class ScriptProcessor extends AbstractProcessor {
|
||||
|
||||
@Override
|
||||
public void execute(IngestDocument document) {
|
||||
ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.INGEST, emptyMap());
|
||||
ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.INGEST);
|
||||
executableScript.setNextVar("ctx", document.getSourceAndMetadata());
|
||||
executableScript.run();
|
||||
}
|
||||
@ -82,6 +82,7 @@ public final class ScriptProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ScriptProcessor create(Map<String, Processor.Factory> registry, String processorTag,
|
||||
Map<String, Object> config) throws Exception {
|
||||
String lang = readOptionalStringProperty(TYPE, processorTag, config, "lang");
|
||||
@ -101,17 +102,21 @@ public final class ScriptProcessor extends AbstractProcessor {
|
||||
throw newConfigurationException(TYPE, processorTag, null, "Only one of [file], [id], or [inline] may be configured");
|
||||
}
|
||||
|
||||
if(params == null) {
|
||||
if (lang == null) {
|
||||
lang = Script.DEFAULT_SCRIPT_LANG;
|
||||
}
|
||||
|
||||
if (params == null) {
|
||||
params = emptyMap();
|
||||
}
|
||||
|
||||
final Script script;
|
||||
if (Strings.hasLength(file)) {
|
||||
script = new Script(file, FILE, lang, params);
|
||||
script = new Script(FILE, lang, file, (Map<String, Object>)params);
|
||||
} else if (Strings.hasLength(inline)) {
|
||||
script = new Script(inline, INLINE, lang, params);
|
||||
script = new Script(INLINE, lang, inline, (Map<String, Object>)params);
|
||||
} else if (Strings.hasLength(id)) {
|
||||
script = new Script(id, STORED, lang, params);
|
||||
script = new Script(STORED, lang, id, (Map<String, Object>)params);
|
||||
} else {
|
||||
throw newConfigurationException(TYPE, processorTag, null, "Could not initialize script");
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class ScriptProcessorTests extends ESTestCase {
|
||||
ScriptService scriptService = mock(ScriptService.class);
|
||||
Script script = new Script("_script");
|
||||
ExecutableScript executableScript = mock(ExecutableScript.class);
|
||||
when(scriptService.executable(any(), any(), any())).thenReturn(executableScript);
|
||||
when(scriptService.executable(any(Script.class), any())).thenReturn(executableScript);
|
||||
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("bytes_in", randomInt());
|
||||
|
@ -58,7 +58,7 @@ public class IndexedExpressionTests extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "scriptTest", "1").setSource("{\"theField\":\"foo\"}").get();
|
||||
try {
|
||||
client().prepareUpdate("test", "scriptTest", "1")
|
||||
.setScript(new Script("script1", ScriptType.STORED, ExpressionScriptEngineService.NAME, null)).get();
|
||||
.setScript(new Script(ScriptType.STORED, ExpressionScriptEngineService.NAME, "script1", Collections.emptyMap())).get();
|
||||
fail("update script should have been rejected");
|
||||
} catch(Exception e) {
|
||||
assertThat(e.getMessage(), containsString("failed to execute script"));
|
||||
@ -67,7 +67,7 @@ public class IndexedExpressionTests extends ESIntegTestCase {
|
||||
try {
|
||||
client().prepareSearch()
|
||||
.setSource(
|
||||
new SearchSourceBuilder().scriptField("test1", new Script("script1", ScriptType.STORED, "expression", null)))
|
||||
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, "expression", "script1", Collections.emptyMap())))
|
||||
.setIndices("test").setTypes("scriptTest").get();
|
||||
fail("search script should have been rejected");
|
||||
} catch(Exception e) {
|
||||
@ -77,7 +77,7 @@ public class IndexedExpressionTests extends ESIntegTestCase {
|
||||
client().prepareSearch("test")
|
||||
.setSource(
|
||||
new SearchSourceBuilder().aggregation(AggregationBuilders.terms("test").script(
|
||||
new Script("script1", ScriptType.STORED, "expression", null)))).get();
|
||||
new Script(ScriptType.STORED, "expression", "script1", Collections.emptyMap())))).get();
|
||||
} catch (Exception e) {
|
||||
assertThat(e.toString(), containsString("scripts of type [stored], operation [aggs] and lang [expression] are disabled"));
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
req.setQuery(QueryBuilders.matchAllQuery())
|
||||
.addSort(SortBuilders.fieldSort("_uid")
|
||||
.order(SortOrder.ASC))
|
||||
.addScriptField("foo", new Script(script, ScriptType.INLINE, "expression", paramsMap));
|
||||
.addScriptField("foo", new Script(ScriptType.INLINE, "expression", script, paramsMap));
|
||||
return req;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "doc", "1").setSource("text", "hello goodbye"),
|
||||
client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"),
|
||||
client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye"));
|
||||
ScoreFunctionBuilder<?> score = ScoreFunctionBuilders.scriptFunction(new Script("1 / _score", ScriptType.INLINE, "expression", null));
|
||||
ScoreFunctionBuilder<?> score = ScoreFunctionBuilders.scriptFunction(new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap()));
|
||||
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
|
||||
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
|
||||
req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent
|
||||
@ -429,13 +429,16 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
req.setQuery(QueryBuilders.matchAllQuery())
|
||||
.addAggregation(
|
||||
AggregationBuilders.stats("int_agg").field("x")
|
||||
.script(new Script("_value * 3", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
ExpressionScriptEngineService.NAME, "_value * 3", Collections.emptyMap())))
|
||||
.addAggregation(
|
||||
AggregationBuilders.stats("double_agg").field("y")
|
||||
.script(new Script("_value - 1.1", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
ExpressionScriptEngineService.NAME, "_value - 1.1", Collections.emptyMap())))
|
||||
.addAggregation(
|
||||
AggregationBuilders.stats("const_agg").field("x") // specifically to test a script w/o _value
|
||||
.script(new Script("3.0", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null))
|
||||
.script(new Script(ScriptType.INLINE,
|
||||
ExpressionScriptEngineService.NAME, "3.0", Collections.emptyMap()))
|
||||
);
|
||||
|
||||
SearchResponse rsp = req.get();
|
||||
@ -469,7 +472,8 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
req.setQuery(QueryBuilders.matchAllQuery())
|
||||
.addAggregation(
|
||||
AggregationBuilders.terms("term_agg").field("text")
|
||||
.script(new Script("_value", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)));
|
||||
.script(
|
||||
new Script(ScriptType.INLINE, ExpressionScriptEngineService.NAME, "_value", Collections.emptyMap())));
|
||||
|
||||
String message;
|
||||
try {
|
||||
@ -559,7 +563,7 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
UpdateRequestBuilder urb = client().prepareUpdate().setIndex("test_index");
|
||||
urb.setType("doc");
|
||||
urb.setId("1");
|
||||
urb.setScript(new Script("0", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null));
|
||||
urb.setScript(new Script(ScriptType.INLINE, ExpressionScriptEngineService.NAME, "0", Collections.emptyMap()));
|
||||
urb.get();
|
||||
fail("Expression scripts should not be allowed to run as update scripts.");
|
||||
} catch (Exception e) {
|
||||
@ -590,7 +594,8 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||
.subAggregation(sum("threeSum").field("three"))
|
||||
.subAggregation(sum("fourSum").field("four"))
|
||||
.subAggregation(bucketScript("totalSum",
|
||||
new Script("_value0 + _value1 + _value2", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null),
|
||||
new Script(ScriptType.INLINE,
|
||||
ExpressionScriptEngineService.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
|
||||
"twoSum", "threeSum", "fourSum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -30,7 +30,6 @@ import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.codehaus.groovy.ast.ClassCodeExpressionTransformer;
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.ast.Parameter;
|
||||
import org.codehaus.groovy.ast.expr.ConstantExpression;
|
||||
import org.codehaus.groovy.ast.expr.Expression;
|
||||
import org.codehaus.groovy.classgen.GeneratorContext;
|
||||
|
@ -90,9 +90,10 @@ public class GroovyIndexedScriptTests extends ESIntegTestCase {
|
||||
.prepareSearch()
|
||||
.setSource(
|
||||
new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).size(1)
|
||||
.scriptField("test1", new Script("script1", ScriptType.STORED, GroovyScriptEngineService.NAME, null))
|
||||
.scriptField("test1",
|
||||
new Script(ScriptType.STORED, GroovyScriptEngineService.NAME, "script1", Collections.emptyMap()))
|
||||
.scriptField("test2",
|
||||
new Script("script2", ScriptType.STORED, GroovyScriptEngineService.NAME, script2Params)))
|
||||
new Script(ScriptType.STORED, GroovyScriptEngineService.NAME, "script2", script2Params)))
|
||||
.setIndices("test").setTypes("scriptTest").get();
|
||||
assertHitCount(searchResponse, 5);
|
||||
assertTrue(searchResponse.getHits().hits().length == 1);
|
||||
@ -118,7 +119,7 @@ public class GroovyIndexedScriptTests extends ESIntegTestCase {
|
||||
.prepareSearch()
|
||||
.setSource(
|
||||
new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).scriptField("test_field",
|
||||
new Script("script1", ScriptType.STORED, GroovyScriptEngineService.NAME, null)))
|
||||
new Script(ScriptType.STORED, GroovyScriptEngineService.NAME, "script1", Collections.emptyMap())))
|
||||
.setIndices("test_index")
|
||||
.setTypes("test_type").get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
@ -135,7 +136,7 @@ public class GroovyIndexedScriptTests extends ESIntegTestCase {
|
||||
client().prepareIndex("test", "scriptTest", "1").setSource("{\"theField\":\"foo\"}").get();
|
||||
try {
|
||||
client().prepareUpdate("test", "scriptTest", "1")
|
||||
.setScript(new Script("script1", ScriptType.STORED, GroovyScriptEngineService.NAME, null)).get();
|
||||
.setScript(new Script(ScriptType.STORED, GroovyScriptEngineService.NAME, "script1", Collections.emptyMap())).get();
|
||||
fail("update script should have been rejected");
|
||||
} catch (Exception e) {
|
||||
assertThat(e.getMessage(), containsString("failed to execute script"));
|
||||
@ -156,7 +157,7 @@ public class GroovyIndexedScriptTests extends ESIntegTestCase {
|
||||
.prepareSearch("test")
|
||||
.setSource(
|
||||
new SearchSourceBuilder().aggregation(AggregationBuilders.terms("test").script(
|
||||
new Script("script1", ScriptType.STORED, GroovyScriptEngineService.NAME, null)))).get();
|
||||
new Script(ScriptType.STORED, GroovyScriptEngineService.NAME, "script1", Collections.emptyMap())))).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
assertThat(searchResponse.getAggregations().get("test"), notNullValue());
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user