gpt4 book ai didi

org.elasticsearch.common.xcontent.XContentParserUtils类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 10:24:40 28 4
gpt4 key购买 nike

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

XContentParserUtils介绍

[英]A set of static methods to get Token from XContentParserwhile checking for their types and throw ParsingException if needed.
[中]一组静态方法,在检查其类型并在需要时抛出ParsingException时,从XContentParserw获取令牌。

代码示例

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

@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation);
  SetOnce<Suggestion> suggestion = new SetOnce<>();
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set);
  return suggestion.get();
}

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

private static Map<String, SearchHits> parseInnerHits(XContentParser parser) throws IOException {
  Map<String, SearchHits> innerHits = new HashMap<>();
  while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
    ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
    String name = parser.currentName();
    ensureExpectedToken(Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    ensureFieldName(parser, parser.nextToken(), SearchHits.Fields.HITS);
    innerHits.put(name, SearchHits.fromXContent(parser));
    ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation);
  }
  return innerHits;
}

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

public static BulkResponse fromXContent(XContentParser parser) throws IOException {
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
        ingestTook = parser.longValue();
      } else if (ERRORS.equals(currentFieldName) == false) {
        throwUnknownField(currentFieldName, parser.getTokenLocation());
        throwUnknownField(currentFieldName, parser.getTokenLocation());
      throwUnknownToken(token, parser.getTokenLocation());

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

public static DocumentField fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
  String fieldName = parser.currentName();
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.START_ARRAY, token, parser::getTokenLocation);
  List<Object> values = new ArrayList<>();
  while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
    values.add(parseFieldsValue(parser));
  }
  return new DocumentField(fieldName, values);
}

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

public static ClusterShardHealth fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
  String shardIdStr = parser.currentName();
  ClusterShardHealth parsed = innerFromXContent(parser, Integer.valueOf(shardIdStr));
  ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation);
  return parsed;
}

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

ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
  itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
} else {
  throwUnknownField(currentFieldName, parser.getTokenLocation());
ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser::getTokenLocation);
token = parser.nextToken();
ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser::getTokenLocation);

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

public static Aggregations fromXContent(XContentParser parser) throws IOException {
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.START_OBJECT) {
        SetOnce<Aggregation> typedAgg = new SetOnce<>();
        String currentField = parser.currentName();
        parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set);
        if (typedAgg.get() != null) {
          aggregations.add(typedAgg.get());
        } else {
          throw new ParsingException(parser.getTokenLocation(),
              String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField));
        }
      }
    }
    return new Aggregations(aggregations);
  }
}

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

to = parser.doubleValue();
} else {
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
  toAsStr = parser.text();
} else {
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
XContentParserUtils.throwUnknownToken(token, parser.getTokenLocation());

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

throws IOException {
if (parser.currentToken() != Token.START_OBJECT && parser.currentToken() != Token.START_ARRAY) {
  throwUnknownToken(parser.currentToken(), parser.getTokenLocation());

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

/**
 * we need to declare parse fields for each metadata field, except for _ID, _INDEX and _TYPE which are
 * handled individually. All other fields are parsed to an entry in the fields map
 */
private static void declareMetaDataFields(ObjectParser<Map<String, Object>, Void> parser) {
  for (String metadatafield : MapperService.getAllMetaFields()) {
    if (metadatafield.equals(Fields._ID) == false && metadatafield.equals(Fields._INDEX) == false
        && metadatafield.equals(Fields._TYPE) == false) {
      if (metadatafield.equals(IgnoredFieldMapper.NAME)) {
        parser.declareObjectArray((map, list) -> {
            @SuppressWarnings("unchecked")
            Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
              v -> new HashMap<String, DocumentField>());
            DocumentField field = new DocumentField(metadatafield, list);
            fieldMap.put(field.getName(), field);
          }, (p, c) -> parseFieldsValue(p),
          new ParseField(metadatafield));
      } else {
        parser.declareField((map, field) -> {
            @SuppressWarnings("unchecked")
            Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
              v -> new HashMap<String, DocumentField>());
            fieldMap.put(field.getName(), field);
          }, (p, c) -> new DocumentField(metadatafield, Collections.singletonList(parseFieldsValue(p))),
          new ParseField(metadatafield), ValueType.VALUE);
      }
    }
  }
}

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

public static ClusterIndexHealth fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
  String index = parser.currentName();
  ClusterIndexHealth parsed = innerFromXContent(parser, index);
  ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation);
  return parsed;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static ShardInfo fromXContent(XContentParser parser) throws IOException {
  XContentParser.Token token = parser.currentToken();
  ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
        successful = parser.intValue();
      } else if (FAILED.equals(currentFieldName) == false) {
        throwUnknownField(currentFieldName, parser.getTokenLocation());
        throwUnknownField(currentFieldName, parser.getTokenLocation());

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

XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
    aggregations::add);

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

to = parser.doubleValue();
} else {
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
  key = parser.text();
} else {
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
  XContentParserUtils.throwUnknownField(currentFieldName, parser.getTokenLocation());
XContentParserUtils.throwUnknownToken(token, parser.getTokenLocation());

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

public static DocumentField fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
  String fieldName = parser.currentName();
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.START_ARRAY, token, parser::getTokenLocation);
  List<Object> values = new ArrayList<>();
  while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
    values.add(parseFieldsValue(parser));
  }
  return new DocumentField(fieldName, values);
}

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

builder.put(key, parser.booleanValue());
} else {
  XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());

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

/**
 * we need to declare parse fields for each metadata field, except for _ID, _INDEX and _TYPE which are
 * handled individually. All other fields are parsed to an entry in the fields map
 */
private static void declareMetaDataFields(ObjectParser<Map<String, Object>, Void> parser) {
  for (String metadatafield : MapperService.getAllMetaFields()) {
    if (metadatafield.equals(Fields._ID) == false && metadatafield.equals(Fields._INDEX) == false
        && metadatafield.equals(Fields._TYPE) == false) {
      if (metadatafield.equals(IgnoredFieldMapper.NAME)) {
        parser.declareObjectArray((map, list) -> {
            @SuppressWarnings("unchecked")
            Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
              v -> new HashMap<String, DocumentField>());
            DocumentField field = new DocumentField(metadatafield, list);
            fieldMap.put(field.getName(), field);
          }, (p, c) -> parseFieldsValue(p),
          new ParseField(metadatafield));
      } else {
        parser.declareField((map, field) -> {
            @SuppressWarnings("unchecked")
            Map<String, DocumentField> fieldMap = (Map<String, DocumentField>) map.computeIfAbsent(Fields.FIELDS,
              v -> new HashMap<String, DocumentField>());
            fieldMap.put(field.getName(), field);
          }, (p, c) -> new DocumentField(metadatafield, Collections.singletonList(parseFieldsValue(p))),
          new ParseField(metadatafield), ValueType.VALUE);
      }
    }
  }
}

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

static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException {
    final ParsedBucket bucket = new ParsedBucket();
    bucket.setKeyed(keyed);
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = parser.currentName();
    if (keyed) {
      ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
      bucket.key = currentFieldName;
      ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    }
    List<Aggregation> aggregations = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
            aggregations::add);
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

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

public static BulkResponse fromXContent(XContentParser parser) throws IOException {
  XContentParser.Token token = parser.nextToken();
  ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
        ingestTook = parser.longValue();
      } else if (ERRORS.equals(currentFieldName) == false) {
        throwUnknownField(currentFieldName, parser.getTokenLocation());
        throwUnknownField(currentFieldName, parser.getTokenLocation());
      throwUnknownToken(token, parser.getTokenLocation());

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

/**
 * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)}
 */
public static ElasticsearchException failureFromXContent(XContentParser parser) throws IOException {
  XContentParser.Token token = parser.currentToken();
  ensureFieldName(parser, token, ERROR);
  token = parser.nextToken();
  if (token.isValue()) {
    return new ElasticsearchException(buildMessage("exception", parser.text(), null));
  }
  ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
  token = parser.nextToken();
  // Root causes are parsed in the innerFromXContent() and are added as suppressed exceptions.
  return innerFromXContent(parser, true);
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com