当前位置: 首页>>代码示例>>Java>>正文


Java XContentParser.Token方法代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentParser.Token方法的典型用法代码示例。如果您正苦于以下问题:Java XContentParser.Token方法的具体用法?Java XContentParser.Token怎么用?Java XContentParser.Token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.xcontent.XContentParser的用法示例。


在下文中一共展示了XContentParser.Token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readValue

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
static Object readValue(XContentParser parser, MapFactory mapFactory, XContentParser.Token token) throws IOException {
    if (token == XContentParser.Token.VALUE_NULL) {
        return null;
    } else if (token == XContentParser.Token.VALUE_STRING) {
        return parser.text();
    } else if (token == XContentParser.Token.VALUE_NUMBER) {
        return parser.numberValue();
    } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
        return parser.booleanValue();
    } else if (token == XContentParser.Token.START_OBJECT) {
        return readMap(parser, mapFactory);
    } else if (token == XContentParser.Token.START_ARRAY) {
        return readList(parser, mapFactory);
    } else if (token == XContentParser.Token.VALUE_EMBEDDED_OBJECT) {
        return parser.binaryValue();
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AbstractXContentParser.java

示例2: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends MetaData.Custom> T fromXContent(Function<String, MetaData.Custom> supplier, XContentParser parser)
    throws IOException {
    XContentParser.Token token;
    String data = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            String currentFieldName = parser.currentName();
            if ("data".equals(currentFieldName)) {
                if (parser.nextToken() != XContentParser.Token.VALUE_STRING) {
                    throw new ElasticsearchParseException("failed to parse snapshottable metadata, invalid data type");
                }
                data = parser.text();
            } else {
                throw new ElasticsearchParseException("failed to parse snapshottable metadata, unknown field [{}]", currentFieldName);
            }
        } else {
            throw new ElasticsearchParseException("failed to parse snapshottable metadata");
        }
    }
    if (data == null) {
        throw new ElasticsearchParseException("failed to parse snapshottable metadata, data not found");
    }
    return (T) supplier.apply(data);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TestCustomMetaData.java

示例3: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public InnerHitsSubSearchContext parse(QueryParseContext parserContext) throws IOException, QueryParsingException {
    String fieldName = null;
    XContentParser.Token token;
    String innerHitName = null;
    SubSearchContext subSearchContext = new SubSearchContext(SearchContext.current());
    try {
        XContentParser parser = parserContext.parser();
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                fieldName = parser.currentName();
            } else if (token.isValue()) {
                if ("name".equals(fieldName)) {
                    innerHitName = parser.textOrNull();
                } else {
                    parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
                }
            } else {
                parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
            }
        }
    } catch (Exception e) {
        throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
    }
    return new InnerHitsSubSearchContext(innerHitName, subSearchContext);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:InnerHitsQueryParserHelper.java

示例4: verifySameTokens

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private void verifySameTokens(XContentParser parser1, XContentParser parser2) throws IOException {
    while (true) {
        XContentParser.Token token1 = parser1.nextToken();
        XContentParser.Token token2 = parser2.nextToken();
        if (token1 == null) {
            assertThat(token2, nullValue());
            return;
        }
        assertThat(token1, equalTo(token2));
        switch (token1) {
            case FIELD_NAME:
                assertThat(parser1.currentName(), equalTo(parser2.currentName()));
                break;
            case VALUE_STRING:
                assertThat(parser1.text(), equalTo(parser2.text()));
                break;
            case VALUE_NUMBER:
                assertThat(parser1.numberType(), equalTo(parser2.numberType()));
                assertThat(parser1.numberValue(), equalTo(parser2.numberValue()));
                break;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:JsonVsCborTests.java

示例5: parseSubArray

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
protected Object[] parseSubArray(SQLXContentSourceContext context, XContentParser parser)
    throws IOException
{
    XContentParser.Token token;
    List<Object> subList = new ArrayList<Object>();

    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
        if (token.isValue()) {
            subList.add(parser.objectText());
        } else if (token == XContentParser.Token.START_ARRAY) {
            subList.add(parseSubArray(context, parser));
        } else if (token == XContentParser.Token.START_OBJECT) {
            subList.add(parser.map());
        } else if (token == XContentParser.Token.VALUE_NULL) {
            subList.add(null);
        } else {
            throw new SQLParseSourceException(context, "Field [" + parser.currentName() + "] has an invalid value");
        }
    }

    return subList.toArray(new Object[subList.size()]);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:SQLArgsParseElement.java

示例6: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
 * Parses bodies of the kind
 *
 * <pre>
 * <code>
 * {
 *      "fieldname1" : {
 *          "origin" : "someValue",
 *          "scale" : "someValue"
 *      },
 *      "multi_value_mode" : "min"
 * }
 * </code>
 * </pre>
 */
@Override
public DFB fromXContent(QueryParseContext context) throws IOException, ParsingException {
    XContentParser parser = context.parser();
    String currentFieldName;
    XContentParser.Token token;
    MultiValueMode multiValueMode = DecayFunctionBuilder.DEFAULT_MULTI_VALUE_MODE;
    String fieldName = null;
    BytesReference functionBytes = null;
    while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (token == XContentParser.Token.START_OBJECT) {
            fieldName = currentFieldName;
            XContentBuilder builder = XContentFactory.jsonBuilder();
            builder.copyCurrentStructure(parser);
            functionBytes = builder.bytes();
        } else if (MULTI_VALUE_MODE.match(currentFieldName)) {
            multiValueMode = MultiValueMode.fromString(parser.text());
        } else {
            throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
        }
    }
    if (fieldName == null || functionBytes == null) {
        throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
    }
    DFB functionBuilder = createFromBytes.apply(fieldName, functionBytes);
    functionBuilder.setMultiValueMode(multiValueMode);
    return functionBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:DecayFunctionParser.java

示例7: parseExclude

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static IncludeExclude parseExclude(XContentParser parser, QueryParseContext context) throws IOException {
    XContentParser.Token token = parser.currentToken();
    if (token == XContentParser.Token.VALUE_STRING) {
        return new IncludeExclude(null, parser.text());
    } else if (token == XContentParser.Token.START_ARRAY) {
        return new IncludeExclude(null, new TreeSet<>(parseArrayToSet(parser)));
    } else {
        throw new IllegalArgumentException("Unrecognized token for an exclude [" + token + "]");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:IncludeExclude.java

示例8: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static ShardInfo fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);

    int total = 0, successful = 0;
    List<Failure> failuresList = null;
    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 (TOTAL.equals(currentFieldName)) {
                total = parser.intValue();
            } else if (SUCCESSFUL.equals(currentFieldName)) {
                successful = parser.intValue();
            } else if (FAILED.equals(currentFieldName) == false) {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (FAILURES.equals(currentFieldName)) {
                failuresList = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    failuresList.add(Failure.fromXContent(parser));
                }
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        }
    }
    Failure[] failures = EMPTY;
    if (failuresList != null) {
        failures = failuresList.toArray(new Failure[failuresList.size()]);
    }
    return new ShardInfo(total, successful, failures);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:ReplicationResponse.java

示例9: parseCreateFieldForString

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
 * Parse a field as though it were a string.
 * @param context parse context used during parsing
 * @param nullValue value to use for null
 * @param defaultBoost default boost value returned unless overwritten in the field
 * @return the parsed field and the boost either parsed or defaulted
 * @throws IOException if thrown while parsing
 */
public static ValueAndBoost parseCreateFieldForString(ParseContext context, String nullValue, float defaultBoost) throws IOException {
    if (context.externalValueSet()) {
        return new ValueAndBoost(context.externalValue().toString(), defaultBoost);
    }
    XContentParser parser = context.parser();
    if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
        return new ValueAndBoost(nullValue, defaultBoost);
    }
    if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
        XContentParser.Token token;
        String currentFieldName = null;
        String value = nullValue;
        float boost = defaultBoost;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
            } else {
                if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
                    value = parser.textOrNull();
                } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
                    boost = parser.floatValue();
                } else {
                    throw new IllegalArgumentException("unknown property [" + currentFieldName + "]");
                }
            }
        }
        return new ValueAndBoost(value, boost);
    }
    return new ValueAndBoost(parser.textOrNull(), defaultBoost);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:39,代码来源:StringFieldMapper.java

示例10: assertBinary

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
protected void assertBinary(XContentBuilder expected, XContentBuilder builder) {
    assertNotNull(builder);
    assertNotNull(expected);

    try {
        XContent xContent = XContentFactory.xContent(builder.contentType());
        XContentParser jsonParser = createParser(xContent, expected.bytes());
        XContentParser testParser = createParser(xContent, builder.bytes());

        while (true) {
            XContentParser.Token token1 = jsonParser.nextToken();
            XContentParser.Token token2 = testParser.nextToken();
            if (token1 == null) {
                assertThat(token2, nullValue());
                return;
            }
            assertThat(token1, equalTo(token2));
            switch (token1) {
                case FIELD_NAME:
                    assertThat(jsonParser.currentName(), equalTo(testParser.currentName()));
                    break;
                case VALUE_STRING:
                    assertThat(jsonParser.text(), equalTo(testParser.text()));
                    break;
                case VALUE_NUMBER:
                    assertThat(jsonParser.numberType(), equalTo(testParser.numberType()));
                    assertThat(jsonParser.numberValue(), equalTo(testParser.numberValue()));
                    break;
            }
        }
    } catch (Exception e) {
        fail("Fail to verify the result of the XContentBuilder: " + e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:AbstractFilteringJsonGeneratorTestCase.java

示例11: serializeObject

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private void serializeObject(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser,
        String objFieldName) throws IOException {
    if (objFieldName != null) {
        path.add(objFieldName);
    }

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.START_OBJECT) {
            serializeObject(settings, sb, path, parser, currentFieldName);
        } else if (token == XContentParser.Token.START_ARRAY) {
            serializeArray(settings, sb, path, parser, currentFieldName);
        } else if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_NULL) {
            serializeValue(settings, sb, path, parser, currentFieldName, true);
        } else {
            serializeValue(settings, sb, path, parser, currentFieldName, false);

        }
    }

    if (objFieldName != null) {
        path.remove(path.size() - 1);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:XContentSettingsLoader.java

示例12: 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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:BlobStoreFormatIT.java

示例13: parseExplanation

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static Explanation parseExplanation(XContentParser parser) throws IOException {
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
    XContentParser.Token token;
    Float value = null;
    String description = null;
    List<Explanation> details = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, () -> parser.getTokenLocation());
        String currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (Fields.VALUE.equals(currentFieldName)) {
            value = parser.floatValue();
        } else if (Fields.DESCRIPTION.equals(currentFieldName)) {
            description = parser.textOrNull();
        } else if (Fields.DETAILS.equals(currentFieldName)) {
            ensureExpectedToken(XContentParser.Token.START_ARRAY, token, () -> parser.getTokenLocation());
            while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                details.add(parseExplanation(parser));
            }
        } else {
            throwUnknownField(currentFieldName, parser.getTokenLocation());
        }
    }
    if (value == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation value");
    }
    if (description == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation description");
    }
    return Explanation.match(value, description, details);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:SearchHit.java

示例14: parseFromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static RescoreBuilder<?> parseFromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    RescoreBuilder<?> rescorer = null;
    Integer windowSize = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            fieldName = parser.currentName();
        } else if (token.isValue()) {
            if (WINDOW_SIZE_FIELD.match(fieldName)) {
                windowSize = parser.intValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support [" + fieldName + "]");
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            // we only have QueryRescorer at this point
            if (QueryRescorerBuilder.NAME.equals(fieldName)) {
                rescorer = QueryRescorerBuilder.fromXContent(parseContext);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support rescorer with name [" + fieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "unexpected token [" + token + "] after [" + fieldName + "]");
        }
    }
    if (rescorer == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing rescore type");
    }
    if (windowSize != null) {
        rescorer.windowSize(windowSize.intValue());
    }
    return rescorer;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:RescoreBuilder.java

示例15: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    boolean queryFound = false;
    float boost = 1.0f;
    String parentType = null;
    boolean score = false;
    String queryName = null;
    InnerHitsSubSearchContext innerHits = null;

    String currentFieldName = null;
    XContentParser.Token token;
    XContentStructure.InnerQuery iq = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            // Usually, the query would be parsed here, but the child
            // type may not have been extracted yet, so use the
            // XContentStructure.<type> facade to parse if available,
            // or delay parsing if not.
            if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
                iq = new XContentStructure.InnerQuery(parseContext, parentType == null ? null : new String[] {parentType});
                queryFound = true;
            } else if ("inner_hits".equals(currentFieldName)) {
                innerHits = innerHitsQueryParserHelper.parse(parseContext);
            } else {
                throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) {
                parentType = parser.text();
            } else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE)) {
                String scoreTypeValue = parser.text();
                if ("score".equals(scoreTypeValue)) {
                    score = true;
                } else if ("none".equals(scoreTypeValue)) {
                    score = false;
                }
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
            }
        }
    }
    if (!queryFound) {
        throw new QueryParsingException(parseContext, "[has_parent] query requires 'query' field");
    }
    if (parentType == null) {
        throw new QueryParsingException(parseContext, "[has_parent] query requires 'parent_type' field");
    }

    Query innerQuery = iq.asQuery(parentType);

    if (innerQuery == null) {
        return null;
    }

    innerQuery.setBoost(boost);
    Query query = createParentQuery(innerQuery, parentType, score, parseContext, innerHits);
    if (query == null) {
        return null;
    }

    query.setBoost(boost);
    if (queryName != null) {
        parseContext.addNamedQuery(queryName, query);
    }
    return query;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:75,代码来源:HasParentQueryParser.java


注:本文中的org.elasticsearch.common.xcontent.XContentParser.Token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。