本文整理了Java中org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken()
方法的一些代码示例,展示了XContentParserUtils.ensureExpectedToken()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentParserUtils.ensureExpectedToken()
方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentParserUtils
类名称:XContentParserUtils
方法名:ensureExpectedToken
[英]Makes sure that provided token is of the expected type
[中]确保提供的令牌是预期的类型
代码示例来源: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
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: org.elasticsearch/elasticsearch
private static Map<String, FieldCapabilities> parseTypeToCapabilities(XContentParser parser, String name) throws IOException {
Map<String, FieldCapabilities> typeToCapabilities = new HashMap<>();
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
String type = parser.currentName();
FieldCapabilities capabilities = FieldCapabilities.fromXContent(name, parser);
typeToCapabilities.put(type, capabilities);
}
return typeToCapabilities;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Makes sure that current token is of type {@link Token#FIELD_NAME} and the field name is equal to the provided one
* @throws ParsingException if the token is not of type {@link Token#FIELD_NAME} or is not equal to the given field name
*/
public static void ensureFieldName(XContentParser parser, Token token, String fieldName) throws IOException {
ensureExpectedToken(Token.FIELD_NAME, token, parser::getTokenLocation);
String currentName = parser.currentName();
if (currentName.equals(fieldName) == false) {
String message = "Failed to parse object: expecting field with name [%s] but found [%s]";
throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, message, fieldName, currentName));
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static GetResult fromXContentEmbedded(XContentParser parser) throws IOException {
XContentParser.Token token = parser.nextToken();
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
return fromXContentEmbedded(parser, null, null, null);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Generate a {@link ElasticsearchException} from a {@link XContentParser}. This does not
* return the original exception type (ie NodeClosedException for example) but just wraps
* the type, the reason and the cause of the exception. It also recursively parses the
* tree structure of the cause, returning it as a tree structure of {@link ElasticsearchException}
* instances.
*/
public static ElasticsearchException fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.nextToken();
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
return innerFromXContent(parser, false);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static List<AliasMetaData> parseAliases(XContentParser parser) throws IOException {
List<AliasMetaData> indexAliases = new ArrayList<>();
// We start at START_OBJECT since parseIndexEntry ensures that
while (parser.nextToken() != Token.END_OBJECT) {
ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
indexAliases.add(AliasMetaData.Builder.fromXContent(parser));
}
return indexAliases;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static GetResult fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.nextToken();
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
return fromXContentEmbedded(parser);
}
代码示例来源: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 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 Status fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token;
if (parser.currentToken() == Token.START_OBJECT) {
token = parser.nextToken();
} else {
token = parser.nextToken();
}
ensureExpectedToken(Token.START_OBJECT, token, parser::getTokenLocation);
token = parser.nextToken();
ensureExpectedToken(Token.FIELD_NAME, token, parser::getTokenLocation);
return innerFromXContent(parser);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static AggregationProfileShardResult fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
ensureExpectedToken(XContentParser.Token.START_ARRAY, token, parser::getTokenLocation);
List<ProfileResult> aggProfileResults = new ArrayList<>();
while((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
aggProfileResults.add(ProfileResult.fromXContent(parser));
}
return new AggregationProfileShardResult(aggProfileResults);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static GetRepositoriesResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
return new GetRepositoriesResponse(RepositoriesMetaData.fromXContent(parser));
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static SearchResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
parser.nextToken();
return innerFromXContent(parser);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static SnapshotIndexShardStatus fromXContent(XContentParser parser, String indexId) throws IOException {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
return PARSER.parse(parser, indexId, parser.currentName());
}
代码示例来源: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
protected static <E extends Suggestion.Entry<?>> void parseEntries(XContentParser parser, Suggestion<E> suggestion,
CheckedFunction<XContentParser, E, IOException> entryParser)
throws IOException {
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation);
while ((parser.nextToken()) != XContentParser.Token.END_ARRAY) {
suggestion.addTerm(entryParser.apply(parser));
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static IndexResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static UpdateResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static DeleteResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}
内容来源于网络,如有侵权,请联系作者删除!