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


Java XContentParser.booleanValue方法代码示例

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


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

示例1: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public SignificanceHeuristic parse(QueryParseContext context)
        throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    String givenName = parser.currentName();
    boolean includeNegatives = false;
    boolean backgroundIsSuperset = true;
    XContentParser.Token token = parser.nextToken();
    while (!token.equals(XContentParser.Token.END_OBJECT)) {
        if (INCLUDE_NEGATIVES_FIELD.match(parser.currentName())) {
            parser.nextToken();
            includeNegatives = parser.booleanValue();
        } else if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
            parser.nextToken();
            backgroundIsSuperset = parser.booleanValue();
        } else {
            throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown field [{}]", givenName, parser.currentName());
        }
        token = parser.nextToken();
    }
    return newHeuristic(includeNegatives, backgroundIsSuperset);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:NXYSignificanceHeuristic.java

示例2: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public SignificanceHeuristic parse(QueryParseContext context) throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    String givenName = parser.currentName();
    boolean backgroundIsSuperset = true;
    XContentParser.Token token = parser.nextToken();
    while (!token.equals(XContentParser.Token.END_OBJECT)) {
        if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
            parser.nextToken();
            backgroundIsSuperset = parser.booleanValue();
        } else {
            throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown field [{}]", givenName, parser.currentName());
        }
        token = parser.nextToken();
    }
    return newHeuristic(true, backgroundIsSuperset);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:GND.java

示例3: 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

示例4: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public CancelAllocationCommand fromXContent(XContentParser parser) throws IOException {
    String index = null;
    int shardId = -1;
    String nodeId = null;
    boolean allowPrimary = false;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("index".equals(currentFieldName)) {
                index = parser.text();
            } else if ("shard".equals(currentFieldName)) {
                shardId = parser.intValue();
            } else if ("node".equals(currentFieldName)) {
                nodeId = parser.text();
            } else if ("allow_primary".equals(currentFieldName) || "allowPrimary".equals(currentFieldName)) {
                allowPrimary = parser.booleanValue();
            } else {
                throw new ElasticsearchParseException("[{}] command does not support field [{}]", NAME, currentFieldName);
            }
        } else {
            throw new ElasticsearchParseException("[{}] command does not support complex json tokens [{}]", NAME, token);
        }
    }
    if (index == null) {
        throw new ElasticsearchParseException("[{}] command missing the index parameter", NAME);
    }
    if (shardId == -1) {
        throw new ElasticsearchParseException("[{}] command missing the shard parameter", NAME);
    }
    if (nodeId == null) {
        throw new ElasticsearchParseException("[{}] command missing the node parameter", NAME);
    }
    return new CancelAllocationCommand(new ShardId(index, shardId), nodeId, allowPrimary);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:40,代码来源:CancelAllocationCommand.java

示例5: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public ShardStateMetaData fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.nextToken();
    if (token == null) {
        return null;
    }
    Boolean primary = null;
    String currentFieldName = null;
    String indexUUID = IndexMetaData.INDEX_UUID_NA_VALUE;
    AllocationId allocationId = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (PRIMARY_KEY.equals(currentFieldName)) {
                primary = parser.booleanValue();
            } else if (INDEX_UUID_KEY.equals(currentFieldName)) {
                indexUUID = parser.text();
            } else if (VERSION_KEY.equals(currentFieldName)) {
                // ES versions before 6.0 wrote this for legacy reasons, just ignore for now and remove in 7.0
            } else {
                throw new CorruptStateException("unexpected field in shard state [" + currentFieldName + "]");
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (ALLOCATION_ID_KEY.equals(currentFieldName)) {
                allocationId = AllocationId.fromXContent(parser);
            } else {
                throw new CorruptStateException("unexpected object in shard state [" + currentFieldName + "]");
            }
        } else {
            throw new CorruptStateException("unexpected token in shard state [" + token.name() + "]");
        }
    }
    if (primary == null) {
        throw new CorruptStateException("missing value for [primary] in shard state");
    }
    return new ShardStateMetaData(primary, indexUUID, allocationId);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:ShardStateMetaData.java

示例6: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static CancelAllocationCommand fromXContent(XContentParser parser) throws IOException {
    String index = null;
    int shardId = -1;
    String nodeId = null;
    boolean allowPrimary = false;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("index".equals(currentFieldName)) {
                index = parser.text();
            } else if ("shard".equals(currentFieldName)) {
                shardId = parser.intValue();
            } else if ("node".equals(currentFieldName)) {
                nodeId = parser.text();
            } else if ("allow_primary".equals(currentFieldName) || "allowPrimary".equals(currentFieldName)) {
                allowPrimary = parser.booleanValue();
            } else {
                throw new ElasticsearchParseException("[{}] command does not support field [{}]", NAME, currentFieldName);
            }
        } else {
            throw new ElasticsearchParseException("[{}] command does not support complex json tokens [{}]", NAME, token);
        }
    }
    if (index == null) {
        throw new ElasticsearchParseException("[{}] command missing the index parameter", NAME);
    }
    if (shardId == -1) {
        throw new ElasticsearchParseException("[{}] command missing the shard parameter", NAME);
    }
    if (nodeId == null) {
        throw new ElasticsearchParseException("[{}] command missing the node parameter", NAME);
    }
    return new CancelAllocationCommand(index, shardId, nodeId, allowPrimary);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:CancelAllocationCommand.java

示例7: fromXContent

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

    String shardIndex = null, nodeId = null;
    int shardId = -1;
    boolean primary = false;
    RestStatus status = null;
    ElasticsearchException reason = 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 (_INDEX.equals(currentFieldName)) {
                shardIndex = parser.text();
            } else if (_SHARD.equals(currentFieldName)) {
                shardId = parser.intValue();
            } else if (_NODE.equals(currentFieldName)) {
                nodeId = parser.text();
            } else if (STATUS.equals(currentFieldName)) {
                status = RestStatus.valueOf(parser.text());
            } else if (PRIMARY.equals(currentFieldName)) {
                primary = parser.booleanValue();
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (REASON.equals(currentFieldName)) {
                reason = ElasticsearchException.fromXContent(parser);
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        }
    }
    return new Failure(new ShardId(shardIndex, IndexMetaData.INDEX_UUID_NA_VALUE, shardId), nodeId, reason, status, primary);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:ReplicationResponse.java

示例8: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    ValuesSourceParser<GeoPoint> vsParser = ValuesSourceParser.geoPoint(aggregationName, InternalGeoBounds.TYPE, context)
            .targetValueType(ValueType.GEOPOINT)
            .formattable(true)
            .build();
    boolean wrapLongitude = true;
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
            
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("wrap_longitude".equals(currentFieldName) || "wrapLongitude".equals(currentFieldName)) {
                wrapLongitude = parser.booleanValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                    + currentFieldName + "].", parser.getTokenLocation());
        }
    }
    return new GeoBoundsAggregator.Factory(aggregationName, vsParser.config(), wrapLongitude);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:GeoBoundsParser.java

示例9: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public ShardStateMetaData fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.nextToken();
    if (token == null) {
        return null;
    }
    long version = -1;
    Boolean primary = null;
    String currentFieldName = null;
    String indexUUID = IndexMetaData.INDEX_UUID_NA_VALUE;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (VERSION_KEY.equals(currentFieldName)) {
                version = parser.longValue();
            } else if (PRIMARY_KEY.equals(currentFieldName)) {
                primary = parser.booleanValue();
            } else if (INDEX_UUID_KEY.equals(currentFieldName)) {
                indexUUID = parser.text();
            } else {
                throw new CorruptStateException("unexpected field in shard state [" + currentFieldName + "]");
            }
        } else {
            throw new CorruptStateException("unexpected token in shard state [" + token.name() + "]");
        }
    }
    if (primary == null) {
        throw new CorruptStateException("missing value for [primary] in shard state");
    }
    if (version == -1) {
        throw new CorruptStateException("missing value for [version] in shard state");
    }
    return new ShardStateMetaData(version, primary, indexUUID);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:ShardStateMetaData.java

示例10: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public AllocateAllocationCommand fromXContent(XContentParser parser) throws IOException {
    String index = null;
    int shardId = -1;
    String nodeId = null;
    boolean allowPrimary = false;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("index".equals(currentFieldName)) {
                index = parser.text();
            } else if ("shard".equals(currentFieldName)) {
                shardId = parser.intValue();
            } else if ("node".equals(currentFieldName)) {
                nodeId = parser.text();
            } else if ("allow_primary".equals(currentFieldName) || "allowPrimary".equals(currentFieldName)) {
                allowPrimary = parser.booleanValue();
            } else {
                throw new ElasticsearchParseException("[{}] command does not support field [{}]", NAME, currentFieldName);
            }
        } else {
            throw new ElasticsearchParseException("[{}] command does not support complex json tokens [{}]", NAME, token);
        }
    }
    if (index == null) {
        throw new ElasticsearchParseException("[{}] command missing the index parameter", NAME);
    }
    if (shardId == -1) {
        throw new ElasticsearchParseException("[{}] command missing the shard parameter", NAME);
    }
    if (nodeId == null) {
        throw new ElasticsearchParseException("[{}] command missing the node parameter", NAME);
    }
    return new AllocateAllocationCommand(new ShardId(index, shardId), nodeId, allowPrimary);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:40,代码来源:AllocateAllocationCommand.java

示例11: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static FetchSourceContext fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    boolean fetchSource = true;
    String[] includes = Strings.EMPTY_ARRAY;
    String[] excludes = Strings.EMPTY_ARRAY;
    if (token == XContentParser.Token.VALUE_BOOLEAN) {
        fetchSource = parser.booleanValue();
    } else if (token == XContentParser.Token.VALUE_STRING) {
        includes = new String[]{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());
        }
        includes = list.toArray(new String[list.size()]);
    } else if (token == XContentParser.Token.START_OBJECT) {
        String currentFieldName = null;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
            } else if (token == XContentParser.Token.START_ARRAY) {
                if (INCLUDES_FIELD.match(currentFieldName)) {
                    List<String> includesList = new ArrayList<>();
                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                        if (token == XContentParser.Token.VALUE_STRING) {
                            includesList.add(parser.text());
                        } else {
                            throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
                                    + " in [" + currentFieldName + "].", parser.getTokenLocation());
                        }
                    }
                    includes = includesList.toArray(new String[includesList.size()]);
                } else if (EXCLUDES_FIELD.match(currentFieldName)) {
                    List<String> excludesList = new ArrayList<>();
                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                        if (token == XContentParser.Token.VALUE_STRING) {
                            excludesList.add(parser.text());
                        } else {
                            throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
                                    + " in [" + currentFieldName + "].", parser.getTokenLocation());
                        }
                    }
                    excludes = excludesList.toArray(new String[excludesList.size()]);
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
                            + " in [" + currentFieldName + "].", parser.getTokenLocation());
                }
            } else if (token == XContentParser.Token.VALUE_STRING) {
                if (INCLUDES_FIELD.match(currentFieldName)) {
                    includes = new String[] {parser.text()};
                } else if (EXCLUDES_FIELD.match(currentFieldName)) {
                    excludes = new String[] {parser.text()};
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
                        + " in [" + currentFieldName + "].", parser.getTokenLocation());
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
                        parser.getTokenLocation());
            }
        }
    } else {
        throw new ParsingException(parser.getTokenLocation(), "Expected one of [" + XContentParser.Token.VALUE_BOOLEAN + ", "
                + XContentParser.Token.START_OBJECT + "] but found [" + token + "]", parser.getTokenLocation());
    }
    return new FetchSourceContext(fetchSource, includes, excludes);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:68,代码来源:FetchSourceContext.java

示例12: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, InternalIPv4Range.TYPE, context)
            .targetValueType(ValueType.IP)
            .formattable(false)
            .build();

    List<RangeAggregator.Range> ranges = null;
    boolean keyed = false;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token == XContentParser.Token.START_ARRAY) {
            if ("ranges".equals(currentFieldName)) {
                ranges = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    double from = Double.NEGATIVE_INFINITY;
                    String fromAsStr = null;
                    double to = Double.POSITIVE_INFINITY;
                    String toAsStr = null;
                    String key = null;
                    String mask = null;
                    String toOrFromOrMaskOrKey = null;
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            toOrFromOrMaskOrKey = parser.currentName();
                        } else if (token == XContentParser.Token.VALUE_NUMBER) {
                            if ("from".equals(toOrFromOrMaskOrKey)) {
                                from = parser.doubleValue();
                            } else if ("to".equals(toOrFromOrMaskOrKey)) {
                                to = parser.doubleValue();
                            }
                        } else if (token == XContentParser.Token.VALUE_STRING) {
                            if ("from".equals(toOrFromOrMaskOrKey)) {
                                fromAsStr = parser.text();
                            } else if ("to".equals(toOrFromOrMaskOrKey)) {
                                toAsStr = parser.text();
                            } else if ("key".equals(toOrFromOrMaskOrKey)) {
                                key = parser.text();
                            } else if ("mask".equals(toOrFromOrMaskOrKey)) {
                                mask = parser.text();
                            }
                        }
                    }
                    RangeAggregator.Range range = new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr);
                    if (mask != null) {
                        parseMaskRange(mask, range, aggregationName, context);
                    }
                    ranges.add(range);
                }
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("keyed".equals(currentFieldName)) {
                keyed = parser.booleanValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (ranges == null) {
        throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalIPv4Range.FACTORY, ranges, keyed);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:81,代码来源:IpRangeParser.java

示例13: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SpanNearQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();

    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    Integer slop = null;
    boolean inOrder = SpanNearQueryBuilder.DEFAULT_IN_ORDER;
    String queryName = null;

    List<SpanQueryBuilder> clauses = new ArrayList<>();

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (CLAUSES_FIELD.match(currentFieldName)) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    QueryBuilder query = parseContext.parseInnerQueryBuilder();
                    if (query instanceof SpanQueryBuilder == false) {
                        throw new ParsingException(parser.getTokenLocation(), "spanNear [clauses] must be of type span query");
                    }
                    clauses.add((SpanQueryBuilder) query);
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[span_near] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if (IN_ORDER_FIELD.match(currentFieldName)) {
                inOrder = parser.booleanValue();
            } else if (SLOP_FIELD.match(currentFieldName)) {
                slop = parser.intValue();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[span_near] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[span_near] query does not support [" + currentFieldName + "]");
        }
    }

    if (clauses.isEmpty()) {
        throw new ParsingException(parser.getTokenLocation(), "span_near must include [clauses]");
    }

    if (slop == null) {
        throw new ParsingException(parser.getTokenLocation(), "span_near must include [slop]");
    }

    SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(clauses.get(0), slop);
    for (int i = 1; i < clauses.size(); i++) {
        queryBuilder.addClause(clauses.get(i));
    }
    queryBuilder.inOrder(inOrder);
    queryBuilder.boost(boost);
    queryBuilder.queryName(queryName);
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:SpanNearQueryBuilder.java

示例14: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, InternalDateRange.TYPE, context)
            .targetValueType(ValueType.DATE)
            .formattable(true)
            .build();

    List<RangeAggregator.Range> ranges = null;
    boolean keyed = false;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token == XContentParser.Token.START_ARRAY) {
            if ("ranges".equals(currentFieldName)) {
                ranges = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    double from = Double.NEGATIVE_INFINITY;
                    String fromAsStr = null;
                    double to = Double.POSITIVE_INFINITY;
                    String toAsStr = null;
                    String key = null;
                    String toOrFromOrKey = null;
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            toOrFromOrKey = parser.currentName();
                        } else if (token == XContentParser.Token.VALUE_NUMBER) {
                            if ("from".equals(toOrFromOrKey)) {
                                from = parser.doubleValue();
                            } else if ("to".equals(toOrFromOrKey)) {
                                to = parser.doubleValue();
                            } else {
                                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName
                                        + "]: [" + currentFieldName + "].", parser.getTokenLocation());
                            }
                        } else if (token == XContentParser.Token.VALUE_STRING) {
                            if ("from".equals(toOrFromOrKey)) {
                                fromAsStr = parser.text();
                            } else if ("to".equals(toOrFromOrKey)) {
                                toAsStr = parser.text();
                            } else if ("key".equals(toOrFromOrKey)) {
                                key = parser.text();
                            } else {
                                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
                            }
                        }
                    }
                    ranges.add(new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr));
                }
            }
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("keyed".equals(currentFieldName)) {
                keyed = parser.booleanValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (ranges == null) {
        throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalDateRange.FACTORY, ranges, keyed);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:76,代码来源:DateRangeParser.java

示例15: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static NestedQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    ScoreMode scoreMode = ScoreMode.Avg;
    String queryName = null;
    QueryBuilder query = null;
    String path = null;
    String currentFieldName = null;
    InnerHitBuilder innerHitBuilder = null;
    boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (QUERY_FIELD.match(currentFieldName)) {
                query = parseContext.parseInnerQueryBuilder();
            } else if (INNER_HITS_FIELD.match(currentFieldName)) {
                innerHitBuilder = InnerHitBuilder.fromXContent(parseContext);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if (PATH_FIELD.match(currentFieldName)) {
                path = parser.text();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
                ignoreUnmapped = parser.booleanValue();
            } else if (SCORE_MODE_FIELD.match(currentFieldName)) {
                scoreMode = HasChildQueryBuilder.parseScoreMode(parser.text());
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
            }
        }
    }
    NestedQueryBuilder queryBuilder =  new NestedQueryBuilder(path, query, scoreMode)
            .ignoreUnmapped(ignoreUnmapped)
            .queryName(queryName)
            .boost(boost);
    if (innerHitBuilder != null) {
        queryBuilder.innerHit(innerHitBuilder, ignoreUnmapped);
    }
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:NestedQueryBuilder.java


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