org.elasticsearch.script.Script类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(1128)

本文整理了Java中org.elasticsearch.script.Script类的一些代码示例,展示了Script类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Script类的具体详情如下:
包路径:org.elasticsearch.script.Script
类名称:Script

Script介绍

[英]Script holds all the parameters necessary to compile or find in cache and then execute a script.
[中]脚本包含编译或在缓存中查找并执行脚本所需的所有参数。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

private static Script deepCopyScript(Script script, SearchContext context) {
  if (script != null) {
    Map<String, Object> params = script.getParams();
    if (params != null) {
      params = deepCopyParams(params, context);
    }
    return new Script(script.getType(), script.getLang(), script.getIdOrCode(), params);
  } else {
    return null;
  }
}

代码示例来源: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

@Override
public String toString() {
  return "script(" + script.toString() + ")";
}

代码示例来源: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

GapPolicy gapPolicy = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
  if (token == XContentParser.Token.FIELD_NAME) {
    currentFieldName = parser.currentName();
  } else if (token == XContentParser.Token.VALUE_STRING) {
    if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
      bucketsPathsMap = new HashMap<>();
      bucketsPathsMap.put("_value", parser.text());
    } else if (GAP_POLICY.match(currentFieldName, parser.getDeprecationHandler())) {
      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(),
    if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      script = Script.parse(parser);
    } else if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
      Map<String, Object> map = parser.map();

代码示例来源:origin: org.elasticsearch/elasticsearch

String currentFieldName = null;
String fieldname = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
  if (token == XContentParser.Token.FIELD_NAME) {
    currentFieldName = parser.currentName();
  } else if (token.isValue()) {
    if (SuggestionBuilder.ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      tmpSuggestion.analyzer(parser.text());
    } else if (SuggestionBuilder.FIELDNAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      fieldname = parser.text();
    } else if (SuggestionBuilder.SIZE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      tmpSuggestion.size(parser.intValue());
    } else if (SuggestionBuilder.SHARDSIZE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                + currentFieldName + "]");
          Script template = Script.parse(parser, Script.DEFAULT_TEMPLATE_LANG);
          tmpSuggestion.collateQuery(template);
        } else if (PhraseSuggestionBuilder.COLLATE_QUERY_PARAMS.match(currentFieldName, parser.getDeprecationHandler())) {

代码示例来源:origin: org.elasticsearch/elasticsearch

while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
  if (token == XContentParser.Token.FIELD_NAME) {
    currentFieldName = parser.currentName();
  } 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 + "]");
    if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      queryName = parser.text();
    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      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

XContentParser.Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
  if (token == XContentParser.Token.FIELD_NAME) {
    currentFieldName = parser.currentName();
  } else if (token.isValue()) {
    if (SearchSourceBuilder.FROM_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      factory.from(parser.intValue());
    } else if (SearchSourceBuilder.SIZE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      factory.size(parser.intValue());
    } else if (SearchSourceBuilder.VERSION_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
      factory.version(parser.booleanValue());
    } else if (SearchSourceBuilder.EXPLAIN_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
            } 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())) {
              if (SearchSourceBuilder.SCRIPT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                script = Script.parse(parser);
              } else {
                throw new ParsingException(parser.getTokenLocation(),

代码示例来源:origin: org.elasticsearch/elasticsearch

public UpdateRequest fromXContent(XContentParser parser) throws IOException {
  Script script = null;
  XContentParser.Token token = parser.nextToken();
  if (token == null) {
    return this;
  int depth = 0;
  while (token != null) {
    token = parser.nextToken();
      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

maxErrors = in.readFloat();
realWordErrorLikelihood = in.readFloat();
confidence = in.readFloat();
gramSize = in.readOptionalVInt();
model = in.readOptionalNamedWriteable(SmoothingModel.class);
separator = in.readString();
if (in.readBoolean()) {
  collateQuery = new Script(in);
collateParams = in.readMap();

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  waitForActiveShards = ActiveShardCount.readFrom(in);
  type = in.readString();
  id = in.readString();
  routing = in.readOptionalString();
  parent = in.readOptionalString();
  if (in.readBoolean()) {
    script = new Script(in);
  }
  retryOnConflict = in.readVInt();
  refreshPolicy = RefreshPolicy.readFrom(in);
  if (in.readBoolean()) {
    doc = new IndexRequest();
    doc.readFrom(in);
  }
  fields = in.readOptionalStringArray();
  fetchSourceContext = in.readOptionalWriteable(FetchSourceContext::new);
  if (in.readBoolean()) {
    upsertRequest = new IndexRequest();
    upsertRequest.readFrom(in);
  }
  docAsUpsert = in.readBoolean();
  version = in.readLong();
  versionType = VersionType.fromValue(in.readByte());
  detectNoop = in.readBoolean();
  scriptedUpsert = in.readBoolean();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Read from a stream.
 */
private void read(StreamInput in) throws IOException {
  field = in.readOptionalString();
  if (in.readBoolean()) {
    script = new Script(in);
  }
  if (in.readBoolean()) {
    valueType = ValueType.readFromStream(in);
  }
  format = in.readOptionalString();
  missing = in.readGenericValue();
  if (in.readBoolean()) {
    timeZone = DateTimeZone.forID(in.readString());
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

Objects.requireNonNull(defaultLang);
Token token = parser.currentToken();
  token = parser.nextToken();
  return new Script(ScriptType.INLINE, defaultLang, parser.text(), Collections.emptyMap());

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Read from a stream.
 */
public BucketScriptPipelineAggregationBuilder(StreamInput in) throws IOException {
  super(in, NAME);
  int mapSize = in.readVInt();
  bucketsPathsMap = new HashMap<>(mapSize);
  for (int i = 0; i < mapSize; i++) {
    bucketsPathsMap.put(in.readString(), in.readString());
  }
  script = new Script(in);
  format = in.readOptionalString();
  gapPolicy = GapPolicy.readFrom(in);
}

代码示例来源:origin: harbby/presto-connectors

@Override
protected Script createSimpleScript(XContentParser parser) throws IOException {
  if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
    return new Script(parser.text());
  } else {
    throw new ScriptParseException("expected a string value for field [{}], but found [{}]", parser.currentName(),
        parser.currentToken());
  }
}

代码示例来源: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.elasticsearch/elasticsearch

public MovFnPipelineAggregationBuilder(StreamInput in) throws IOException {
  super(in, NAME);
  bucketsPathString = in.readString();
  script = new Script(in);
  format = in.readOptionalString();
  gapPolicy = GapPolicy.readFrom(in);
  window = in.readInt();
}

代码示例来源:origin: NLPchina/elasticsearch-sql

if(kv.value.toString().contains("doc[")) {
  String script = kv.value +  "; return " + kv.key;
  terms.script(new Script(script));
} else {
  value = kv.value.toString();
    case "include":
      try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, value)) {
        parser.nextToken();
        include = IncludeExclude.parseInclude(parser);
      } catch (IOException e) {
    case "exclude":
      try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, value)) {
        parser.nextToken();
        exclude = IncludeExclude.parseExclude(parser);
      } catch (IOException e) {

代码示例来源:origin: org.elasticsearch/elasticsearch

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 ["
    (parser, context) -> Script.parse(parser),
    Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING);
  if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
    return DateTimeZone.forID(p.text());
  } else {

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Read from a stream.
 */
public BucketSelectorPipelineAggregationBuilder(StreamInput in) throws IOException {
  super(in, NAME);
  int mapSize = in.readVInt();
  bucketsPathsMap = new HashMap<>(mapSize);
  for (int i = 0; i < mapSize; i++) {
    bucketsPathsMap.put(in.readString(), in.readString());
  }
  script = new Script(in);
  gapPolicy = GapPolicy.readFrom(in);
}

相关文章