本文整理了Java中org.elasticsearch.common.xcontent.XContentParserUtils.ensureFieldName()
方法的一些代码示例,展示了XContentParserUtils.ensureFieldName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentParserUtils.ensureFieldName()
方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentParserUtils
类名称:XContentParserUtils
方法名:ensureFieldName
[英]Makes sure that current token is of type Token#FIELD_NAME and the field name is equal to the provided one
[中]确保当前令牌的类型为token#FIELD _NAME,并且字段名与提供的相同
代码示例来源: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
/**
* 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);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.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: apache/servicemix-bundles
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: com.strapdata.elasticsearch/elasticsearch
public static SearchProfileShardResults fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
Map<String, ProfileShardResult> searchProfileResults = new HashMap<>();
ensureFieldName(parser, parser.nextToken(), SHARDS_FIELD);
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.nextToken(), parser::getTokenLocation);
while((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
parseSearchProfileResultsEntry(parser, searchProfileResults);
}
ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation);
return new SearchProfileShardResults(searchProfileResults);
}
代码示例来源:origin: org.elasticsearch.client/elasticsearch-rest-high-level-client
public static PutRoleResponse fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();
}
// parse extraneous wrapper
ensureExpectedToken(Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
ensureFieldName(parser, parser.nextToken(), "role");
parser.nextToken();
final PutRoleResponse roleResponse = PARSER.parse(parser, null);
ensureExpectedToken(Token.END_OBJECT, parser.nextToken(), parser::getTokenLocation);
return roleResponse;
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* 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);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.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);
}
代码示例来源:origin: com.strapdata.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);
}
内容来源于网络,如有侵权,请联系作者删除!