本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentParser.currentToken方法的典型用法代码示例。如果您正苦于以下问题:Java XContentParser.currentToken方法的具体用法?Java XContentParser.currentToken怎么用?Java XContentParser.currentToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.xcontent.XContentParser
的用法示例。
在下文中一共展示了XContentParser.currentToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static StoredFieldsContext fromXContent(String fieldName, QueryParseContext context) throws IOException {
XContentParser parser = context.parser();
XContentParser.Token token = parser.currentToken();
if (token == XContentParser.Token.VALUE_STRING) {
return fromList(Collections.singletonList(parser.text()));
} else if (token == XContentParser.Token.START_ARRAY) {
ArrayList<String> list = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
list.add(parser.text());
}
return fromList(list);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Expected [" + XContentParser.Token.VALUE_STRING + "] or ["
+ XContentParser.Token.START_ARRAY + "] in [" + fieldName + "] but found [" + token + "]",
parser.getTokenLocation());
}
}
示例2: failureFromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
* 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);
}
示例3: readMap
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
static Map<String, Object> readMap(XContentParser parser, MapFactory mapFactory) throws IOException {
Map<String, Object> map = mapFactory.newMap();
XContentParser.Token token = parser.currentToken();
if (token == null) {
token = parser.nextToken();
}
if (token == XContentParser.Token.START_OBJECT) {
token = parser.nextToken();
}
for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) {
// Must point to field name
String fieldName = parser.currentName();
// And then the value...
token = parser.nextToken();
Object value = readValue(parser, mapFactory, token);
map.put(fieldName, value);
}
return map;
}
示例4: parse
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static Fuzziness parse(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
switch (token) {
case VALUE_STRING:
case VALUE_NUMBER:
final String fuzziness = parser.text();
if (AUTO.asString().equalsIgnoreCase(fuzziness)) {
return AUTO;
}
try {
final int minimumSimilarity = Integer.parseInt(fuzziness);
switch (minimumSimilarity) {
case 0:
return ZERO;
case 1:
return ONE;
case 2:
return TWO;
default:
return build(fuzziness);
}
} catch (NumberFormatException ex) {
return build(fuzziness);
}
default:
throw new IllegalArgumentException("Can't parse fuzziness on token: [" + token + "]");
}
}
示例5: fromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static CategoryQueryContext fromXContent(QueryParseContext context) throws IOException {
XContentParser parser = context.parser();
XContentParser.Token token = parser.currentToken();
Builder builder = builder();
if (token == XContentParser.Token.START_OBJECT) {
CATEGORY_PARSER.parse(parser, builder, null);
} else if (token == XContentParser.Token.VALUE_STRING) {
builder.setCategory(parser.text());
} else {
throw new ElasticsearchParseException("category context must be an object or string");
}
return builder.build();
}
示例6: parse
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public void parse(XContentParser parser, SearchContext context) throws Exception {
XContentParser.Token token = parser.currentToken();
if (token.isValue()) {
context.trackScores(parser.booleanValue());
}
}
示例7: parse
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public void parse(XContentParser parser, SearchContext context) throws Exception {
XContentParser.Token token = parser.currentToken();
if (token.isValue()) {
context.minimumScore(parser.floatValue());
}
}
示例8: parse
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SignificanceHeuristic parse(QueryParseContext context)
throws IOException, QueryShardException {
XContentParser parser = context.parser();
// move to the closing bracket
if (!parser.nextToken().equals(XContentParser.Token.END_OBJECT)) {
throw new ElasticsearchParseException(
"failed to parse [jlh] significance heuristic. expected an empty object, but found [{}] instead",
parser.currentToken());
}
return new JLHScore();
}
示例9: parse
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public SignificanceHeuristic parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher, SearchContext context)
throws IOException, QueryParsingException {
// move to the closing bracket
if (!parser.nextToken().equals(XContentParser.Token.END_OBJECT)) {
throw new ElasticsearchParseException("failed to parse [percentage] significance heuristic. expected an empty object, but got [{}] instead", parser.currentToken());
}
return new PercentageScore();
}
示例10: testParseGeoPointArrayTooManyValues
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testParseGeoPointArrayTooManyValues() throws IOException {
double lat = 0.0;
double lon = 0.0;
double elev = 0.0;
XContentBuilder json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).value(elev).endArray().endObject();
XContentParser parser = createParser(json);
while (parser.currentToken() != Token.START_ARRAY) {
parser.nextToken();
}
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
assertThat(e.getMessage(), is("only two values allowed"));
}
示例11: testParseGeoPointInvalidType
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testParseGeoPointInvalidType() throws IOException {
XContentBuilder json = jsonBuilder().startObject().field("foo", 5).endObject();
XContentParser parser = createParser(json);
while (parser.currentToken() != Token.VALUE_NUMBER) {
parser.nextToken();
}
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
assertThat(e.getMessage(), is("geo_point expected"));
}
示例12: parseArrayToSet
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static Set<BytesRef> parseArrayToSet(XContentParser parser) throws IOException {
final Set<BytesRef> set = new HashSet<>();
if (parser.currentToken() != XContentParser.Token.START_ARRAY) {
throw new ElasticsearchParseException("Missing start of array in include/exclude clause");
}
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
if (!parser.currentToken().isValue()) {
throw new ElasticsearchParseException("Array elements in include/exclude clauses should be string values");
}
set.add(new BytesRef(parser.text()));
}
return set;
}
示例13: fromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SearchHits fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
parser.nextToken();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
}
XContentParser.Token token = parser.currentToken();
String currentFieldName = null;
List<SearchHit> hits = new ArrayList<>();
long totalHits = 0;
float maxScore = 0f;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (Fields.TOTAL.equals(currentFieldName)) {
totalHits = parser.longValue();
} else if (Fields.MAX_SCORE.equals(currentFieldName)) {
maxScore = parser.floatValue();
} else {
throwUnknownField(currentFieldName, parser.getTokenLocation());
}
} else if (token == XContentParser.Token.VALUE_NULL) {
if (Fields.MAX_SCORE.equals(currentFieldName)) {
maxScore = Float.NaN; // NaN gets rendered as null-field
} else {
throwUnknownField(currentFieldName, parser.getTokenLocation());
}
} else if (token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
hits.add(SearchHit.fromXContent(parser));
}
}
}
SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[hits.size()]), totalHits,
maxScore);
return searchHits;
}
示例14: fromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static BlobObj fromXContent(XContentParser parser) throws IOException {
String text = null;
XContentParser.Token token = parser.currentToken();
if (token == null) {
token = parser.nextToken();
}
if (token == XContentParser.Token.START_OBJECT) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token != XContentParser.Token.FIELD_NAME) {
throw new ElasticsearchParseException("unexpected token [{}]", token);
}
String currentFieldName = parser.currentName();
token = parser.nextToken();
if (token.isValue()) {
if ("text" .equals(currentFieldName)) {
text = parser.text();
} else {
throw new ElasticsearchParseException("unexpected field [{}]", currentFieldName);
}
} else {
throw new ElasticsearchParseException("unexpected token [{}]", token);
}
}
}
if (text == null) {
throw new ElasticsearchParseException("missing mandatory parameter text");
}
return new BlobObj(text);
}
示例15: fromXContent
import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
* Parses shard snapshot metadata
*
* @param parser parser
* @return shard snapshot metadata
*/
public static BlobStoreIndexShardSnapshot fromXContent(XContentParser parser) throws IOException {
String snapshot = null;
long indexVersion = -1;
long startTime = 0;
long time = 0;
int numberOfFiles = 0;
long totalSize = 0;
List<FileInfo> indexFiles = new ArrayList<>();
if (parser.currentToken() == null) { // fresh parser? move to the first token
parser.nextToken();
}
XContentParser.Token token = parser.currentToken();
if (token == XContentParser.Token.START_OBJECT) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
String currentFieldName = parser.currentName();
token = parser.nextToken();
if (token.isValue()) {
if (PARSE_NAME.match(currentFieldName)) {
snapshot = parser.text();
} else if (PARSE_INDEX_VERSION.match(currentFieldName)) {
// The index-version is needed for backward compatibility with v 1.0
indexVersion = parser.longValue();
} else if (PARSE_START_TIME.match(currentFieldName)) {
startTime = parser.longValue();
} else if (PARSE_TIME.match(currentFieldName)) {
time = parser.longValue();
} else if (PARSE_NUMBER_OF_FILES.match(currentFieldName)) {
numberOfFiles = parser.intValue();
} else if (PARSE_TOTAL_SIZE.match(currentFieldName)) {
totalSize = parser.longValue();
} else {
throw new ElasticsearchParseException("unknown parameter [{}]", currentFieldName);
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (PARSE_FILES.match(currentFieldName)) {
while ((parser.nextToken()) != XContentParser.Token.END_ARRAY) {
indexFiles.add(FileInfo.fromXContent(parser));
}
} else {
throw new ElasticsearchParseException("unknown parameter [{}]", currentFieldName);
}
} else {
throw new ElasticsearchParseException("unexpected token [{}]", token);
}
} else {
throw new ElasticsearchParseException("unexpected token [{}]", token);
}
}
}
return new BlobStoreIndexShardSnapshot(snapshot, indexVersion, Collections.unmodifiableList(indexFiles),
startTime, time, numberOfFiles, totalSize);
}