本文整理了Java中org.elasticsearch.script.Script.parse()
方法的一些代码示例,展示了Script.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Script.parse()
方法的具体详情如下:
包路径:org.elasticsearch.script.Script
类名称:Script
方法名:parse
[英]Parse the script configured in the given settings.
[中]解析在给定设置中配置的脚本。
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Convenience method to call {@link Script#parse(XContentParser, String)}
* using the default scripting language.
*/
public static Script parse(XContentParser parser) throws IOException {
return parse(parser, DEFAULT_SCRIPT_LANG);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Parse the script configured in the given settings.
*/
public static Script parse(Settings settings) {
try (XContentBuilder builder = JsonXContent.contentBuilder()){
builder.startObject();
settings.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
try (InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, stream)) {
return parse(parser);
}
} catch (IOException e) {
// it should not happen since we are not actually reading from a stream but an in-memory byte[]
throw new IllegalStateException(e);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static Script extractConditional(Map<String, Object> config) throws IOException {
Object scriptSource = config.remove("if");
if (scriptSource != null) {
try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent)
.map(normalizeScript(scriptSource));
InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, stream)) {
return Script.parse(parser);
}
}
return null;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Similarity apply(Settings settings, Version indexCreatedVersion, ScriptService scriptService) {
boolean discountOverlaps = settings.getAsBoolean(SimilarityProviders.DISCOUNT_OVERLAPS, true);
Settings scriptSettings = settings.getAsSettings("script");
Script script = Script.parse(scriptSettings);
SimilarityScript.Factory scriptFactory = scriptService.compile(script, SimilarityScript.CONTEXT);
Settings weightScriptSettings = settings.getAsSettings("weight_script");
Script weightScript = null;
SimilarityWeightScript.Factory weightScriptFactory = null;
if (weightScriptSettings.isEmpty() == false) {
weightScript = Script.parse(weightScriptSettings);
weightScriptFactory = scriptService.compile(weightScript, SimilarityWeightScript.CONTEXT);
}
return new ScriptedSimilarity(
weightScript == null ? null : weightScript.toString(),
weightScriptFactory == null ? null : weightScriptFactory::newInstance,
script.toString(), scriptFactory::newInstance, discountOverlaps);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
currentFieldName = parser.currentName();
} else if ("script".equals(currentFieldName)) {
script = Script.parse(parser);
} else if ("scripted_upsert".equals(currentFieldName)) {
scriptedUpsert = parser.booleanValue();
代码示例来源:origin: org.elasticsearch/elasticsearch
gapPolicy = GapPolicy.parse(parser.text(), parser.getTokenLocation());
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
script = Script.parse(parser);
} else if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
Map<String, Object> map = parser.map();
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
/**
* Convenience method to call {@link Script#parse(XContentParser, String)}
* using the default scripting language.
*/
public static Script parse(XContentParser parser) throws IOException {
return parse(parser, DEFAULT_SCRIPT_LANG);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
/**
* Convenience method to call {@link Script#parse(XContentParser, String)}
* using the default scripting language.
*/
public static Script parse(XContentParser parser) throws IOException {
return parse(parser, DEFAULT_SCRIPT_LANG);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
gapPolicy = GapPolicy.parse(parser.text(), parser.getTokenLocation());
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
script = Script.parse(parser);
} else if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
Map<String, Object> map = parser.map();
代码示例来源:origin: org.elasticsearch/elasticsearch
} else if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.VALUE_STRING) {
if (INIT_SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
initScript = Script.parse(parser);
} else if (MAP_SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
mapScript = Script.parse(parser);
} else if (COMBINE_SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
combineScript = Script.parse(parser);
} else if (REDUCE_SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
reduceScript = Script.parse(parser);
} else if (token == XContentParser.Token.START_OBJECT &&
PARAMS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
代码示例来源:origin: org.elasticsearch/elasticsearch
public static SignificanceHeuristic parse(XContentParser parser)
throws IOException, QueryShardException {
String heuristicName = parser.currentName();
Script script = null;
XContentParser.Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token.equals(XContentParser.Token.FIELD_NAME)) {
currentFieldName = parser.currentName();
} else {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName);
}
}
}
if (script == null) {
throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. no script found in script_heuristic", heuristicName);
}
return new ScriptHeuristic(script);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static ScriptScoreFunctionBuilder fromXContent(XContentParser parser)
throws IOException, ParsingException {
Script script = null;
String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
}
}
}
if (script == null) {
throw new ParsingException(parser.getTokenLocation(), NAME + " requires 'script' field");
}
return new ScriptScoreFunctionBuilder(script);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
} else if (token == XContentParser.Token.START_OBJECT) {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
boost = parser.floatValue();
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
代码示例来源:origin: org.elasticsearch/elasticsearch
(parser, context) -> Script.parse(parser),
Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING);
代码示例来源:origin: org.elasticsearch/elasticsearch
} else if (token.isValue()) {
if (SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else if (IGNORE_FAILURE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
ignoreFailure = parser.booleanValue();
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName
代码示例来源:origin: org.elasticsearch/elasticsearch
static <VB extends CompositeValuesSourceBuilder<VB>, T> void declareValuesSourceFields(AbstractObjectParser<VB, T> objectParser,
ValueType targetValueType) {
objectParser.declareField(VB::field, XContentParser::text,
new ParseField("field"), ObjectParser.ValueType.STRING);
objectParser.declareField(VB::missing, XContentParser::objectText,
new ParseField("missing"), ObjectParser.ValueType.VALUE);
objectParser.declareBoolean(VB::missingBucket, new ParseField("missing_bucket"));
objectParser.declareField(VB::valueType, p -> {
ValueType valueType = ValueType.resolveForScript(p.text());
if (targetValueType != null && valueType.isNotA(targetValueType)) {
throw new ParsingException(p.getTokenLocation(),
"Aggregation [" + objectParser.getName() + "] was configured with an incompatible value type ["
+ valueType + "]. It can only work on value of type ["
+ targetValueType + "]");
}
return valueType;
}, new ParseField("value_type"), ObjectParser.ValueType.STRING);
objectParser.declareField(VB::script,
(parser, context) -> Script.parse(parser), Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING);
objectParser.declareField(VB::order, XContentParser::text, new ParseField("order"), ObjectParser.ValueType.STRING);
}
代码示例来源:origin: org.codelibs.elasticsearch.module/analysis-common
public PredicateTokenFilterScriptFactory(IndexSettings indexSettings, String name, Settings settings, ScriptService scriptService) {
super(indexSettings, name, settings);
Settings scriptSettings = settings.getAsSettings("script");
Script script = Script.parse(scriptSettings);
if (script.getType() != ScriptType.INLINE) {
throw new IllegalArgumentException("Cannot use stored scripts in tokenfilter [" + name + "]");
}
this.factory = scriptService.compile(script, AnalysisPredicateScript.CONTEXT);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
minimumShouldMatchScript = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support ["
代码示例来源:origin: org.elasticsearch/elasticsearch
} else if (token.isValue()) {
if (SearchSourceBuilder.SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else if (SearchSourceBuilder.IGNORE_FAILURE_FIELD.match(currentFieldName,
parser.getDeprecationHandler())) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
代码示例来源:origin: org.elasticsearch/elasticsearch
+ currentFieldName + "]");
Script template = Script.parse(parser, Script.DEFAULT_TEMPLATE_LANG);
tmpSuggestion.collateQuery(template);
} else if (PhraseSuggestionBuilder.COLLATE_QUERY_PARAMS.match(currentFieldName, parser.getDeprecationHandler())) {
内容来源于网络,如有侵权,请联系作者删除!