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


Java XContentParser.nextToken方法代码示例

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


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

示例1: testFromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testFromXContent() throws IOException {
    HighlightField highlightField = createTestItem();
    XContentType xcontentType = randomFrom(XContentType.values());
    XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    builder.startObject(); // we need to wrap xContent output in proper object to create a parser for it
    builder = highlightField.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();
    XContentParser parser = createParser(builder);
    parser.nextToken(); // skip to the opening object token, fromXContent advances from here and starts with the field name
    parser.nextToken();
    HighlightField parsedField = HighlightField.fromXContent(parser);
    assertEquals(highlightField, parsedField);
    if (highlightField.fragments() != null) {
        assertEquals(XContentParser.Token.END_ARRAY, parser.currentToken());
    }
    assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
    assertNull(parser.nextToken());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:HighlightFieldTests.java

示例2: parse

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

    ValuesSourceParser vsParser = ValuesSourceParser.any(aggregationName, InternalMissing.TYPE, context)
            .scriptable(false)
            .build();

    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 {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    return new MissingAggregator.Factory(aggregationName, vsParser.config());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:MissingParser.java

示例3: parseCompoundSortField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static void parseCompoundSortField(QueryParseContext context, List<SortBuilder<?>> sortFields)
        throws IOException {
    XContentParser.Token token;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            String fieldName = parser.currentName();
            token = parser.nextToken();
            if (token == XContentParser.Token.VALUE_STRING) {
                SortOrder order = SortOrder.fromString(parser.text());
                sortFields.add(fieldOrScoreSort(fieldName).order(order));
            } else {
                if (PARSERS.containsKey(fieldName)) {
                    sortFields.add(PARSERS.get(fieldName).fromXContent(context, fieldName));
                } else {
                    sortFields.add(FieldSortBuilder.fromXContent(context, fieldName));
                }
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SortBuilder.java

示例4: parse

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

    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 (token == XContentParser.Token.VALUE_STRING) {
            if ("path".equals(currentFieldName)) {
                path = parser.text();
            } 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 (path == null) {
        // "field" doesn't exist, so we fall back to the context of the ancestors
        throw new SearchParseException(context, "Missing [path] field for nested aggregation [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new NestedAggregator.Factory(aggregationName, path);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:NestedParser.java

示例5: parseNumberVariable

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private AbstractDistanceScoreFunction parseNumberVariable(String fieldName, XContentParser parser, QueryParseContext parseContext,
        NumberFieldMapper.NumberFieldType fieldType, MultiValueMode mode) throws IOException {
    XContentParser.Token token;
    String parameterName = null;
    double scale = 0;
    double origin = 0;
    double decay = 0.5;
    double offset = 0.0d;
    boolean scaleFound = false;
    boolean refFound = false;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            parameterName = parser.currentName();
        } else if (parameterName.equals(DecayFunctionBuilder.SCALE)) {
            scale = parser.doubleValue();
            scaleFound = true;
        } else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
            decay = parser.doubleValue();
        } else if (parameterName.equals(DecayFunctionBuilder.ORIGIN)) {
            origin = parser.doubleValue();
            refFound = true;
        } else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) {
            offset = parser.doubleValue();
        } else {
            throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
        }
    }
    if (!scaleFound || !refFound) {
        throw new ElasticsearchParseException("both [{}] and [{}] must be set for numeric fields.", DecayFunctionBuilder.SCALE, DecayFunctionBuilder.ORIGIN);
    }
    IndexNumericFieldData numericFieldData = parseContext.getForField(fieldType);
    return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:DecayFunctionParser.java

示例6: testGeoDistanceSortCanBeParsedFromGeoHash

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testGeoDistanceSortCanBeParsedFromGeoHash() throws IOException {
    String json = "{\n" +
            "    \"VDcvDuFjE\" : [ \"7umzzv8eychg\", \"dmdgmt5z13uw\", " +
            "    \"ezu09wxw6v4c\", \"kc7s3515p6k6\", \"jgeuvjwrmfzn\", \"kcpcfj7ruyf8\" ],\n" +
            "    \"unit\" : \"m\",\n" +
            "    \"distance_type\" : \"arc\",\n" +
            "    \"mode\" : \"MAX\",\n" +
            "    \"nested_filter\" : {\n" +
            "      \"ids\" : {\n" +
            "        \"type\" : [ ],\n" +
            "        \"values\" : [ ],\n" +
            "        \"boost\" : 5.711116\n" +
            "      }\n" +
            "    },\n" +
            "    \"validation_method\" : \"STRICT\"\n" +
            "  }";
    XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
    itemParser.nextToken();

    QueryParseContext context = new QueryParseContext(itemParser);

    GeoDistanceSortBuilder result = GeoDistanceSortBuilder.fromXContent(context, json);
    assertEquals("[-19.700583312660456, -2.8225036337971687, "
            + "31.537466906011105, -74.63590376079082, "
            + "43.71844606474042, -5.548660643398762, "
            + "-37.20467280596495, 38.71751043945551, "
            + "-69.44606635719538, 84.25200328230858, "
            + "-39.03717711567879, 44.74099852144718]", Arrays.toString(result.points()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:GeoDistanceSortBuilderTests.java

示例7: parseIds

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static void parseIds(XContentParser parser, List<Item> items, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, @Nullable String defaultRouting) throws IOException {
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
        if (!token.isValue()) {
            throw new IllegalArgumentException("ids array element should only contain ids");
        }
        items.add(new Item(defaultIndex, defaultType, parser.text()).fields(defaultFields).fetchSourceContext(defaultFetchSource).routing(defaultRouting));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:MultiGetRequest.java

示例8: testParseValidFromStrings

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testParseValidFromStrings() throws Exception {
    int precision = randomIntBetween(1, 12);
    XContentParser stParser = createParser(JsonXContent.jsonXContent, 
            "{\"field\":\"my_loc\", \"precision\":\"" + precision + "\", \"size\": \"500\", \"shard_size\": \"550\"}");
    QueryParseContext parseContext = new QueryParseContext(stParser);
    XContentParser.Token token = stParser.nextToken();
    assertSame(XContentParser.Token.START_OBJECT, token);
    // can create a factory
    assertNotNull(GeoGridAggregationBuilder.parse("geohash_grid", parseContext));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:GeoHashGridParserTests.java

示例9: parseSingleRescoreContext

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void parseSingleRescoreContext(XContentParser parser, SearchContext context) throws Exception {
    String fieldName = null;
    RescoreSearchContext rescoreContext = null;
    Integer windowSize = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            fieldName = parser.currentName();
            if (QueryRescorer.NAME.equals(fieldName)) {
                // we only have one at this point
                Rescorer rescorer = QueryRescorer.INSTANCE;
                token = parser.nextToken();
                if (token != XContentParser.Token.START_OBJECT) {
                    throw new ElasticsearchParseException("rescore type malformed, must start with start_object");
                }
                rescoreContext = rescorer.parse(parser, context);
            }
        } else if (token.isValue()) {
            if ("window_size".equals(fieldName)) {
                windowSize = parser.intValue();
            } else {
                throw new IllegalArgumentException("rescore doesn't support [" + fieldName + "]");
            }
        }
    }
    if (rescoreContext == null) {
        throw new IllegalArgumentException("missing rescore type");
    }
    if (windowSize != null) {
        rescoreContext.setWindowSize(windowSize.intValue());
    }
    context.addRescore(rescoreContext);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:RescoreParseElement.java

示例10: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public RescoreSearchContext parse(XContentParser parser, SearchContext context) throws IOException {
    Token token;
    String fieldName = null;
    QueryRescoreContext rescoreContext = new QueryRescoreContext(this);
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            fieldName = parser.currentName();
            if ("rescore_query".equals(fieldName)) {
                ParsedQuery parsedQuery = context.queryParserService().parse(parser);
                rescoreContext.setParsedQuery(parsedQuery);
            }
        } else if (token.isValue()) {
            if ("query_weight".equals(fieldName)) {
                rescoreContext.setQueryWeight(parser.floatValue());
            } else if ("rescore_query_weight".equals(fieldName)) {
                rescoreContext.setRescoreQueryWeight(parser.floatValue());
            } else if ("score_mode".equals(fieldName)) {
                String sScoreMode = parser.text();
                if ("avg".equals(sScoreMode)) {
                    rescoreContext.setScoreMode(ScoreMode.Avg);
                } else if ("max".equals(sScoreMode)) {
                    rescoreContext.setScoreMode(ScoreMode.Max);
                } else if ("min".equals(sScoreMode)) {
                    rescoreContext.setScoreMode(ScoreMode.Min);
                } else if ("total".equals(sScoreMode)) {
                    rescoreContext.setScoreMode(ScoreMode.Total);
                } else if ("multiply".equals(sScoreMode)) {
                    rescoreContext.setScoreMode(ScoreMode.Multiply);
                } else {
                    throw new IllegalArgumentException("[rescore] illegal score_mode [" + sScoreMode + "]");
                }
            } else {
                throw new IllegalArgumentException("rescore doesn't support [" + fieldName + "]");
            }
        }
    }
    return rescoreContext;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:40,代码来源:QueryRescorer.java

示例11: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SamplerAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    XContentParser.Token token;
    String currentFieldName = null;
    Integer shardSize = null;

    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_NUMBER) {
            if (SamplerAggregator.SHARD_SIZE_FIELD.match(currentFieldName)) {
                shardSize = parser.intValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unsupported property \"" + currentFieldName + "\" for aggregation \"" + aggregationName);
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(),
                    "Unsupported property \"" + currentFieldName + "\" for aggregation \"" + aggregationName);
        }
    }

    SamplerAggregationBuilder factory = new SamplerAggregationBuilder(aggregationName);
    if (shardSize != null) {
        factory.shardSize(shardSize);
    }
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:SamplerAggregationBuilder.java

示例12: testParseErrorOnBooleanPrecision

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testParseErrorOnBooleanPrecision() throws Exception {
    XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":false}");
    QueryParseContext parseContext = new QueryParseContext(stParser);
    XContentParser.Token token = stParser.nextToken();
    assertSame(XContentParser.Token.START_OBJECT, token);
    try {
        GeoGridAggregationBuilder.parse("geohash_grid", parseContext);
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("[geohash_grid] precision doesn't support values of type: VALUE_BOOLEAN", ex.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:GeoHashGridParserTests.java

示例13: testParseGeoPointArrayWrongType

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void testParseGeoPointArrayWrongType() throws IOException {
    double lat = 0.0;
    boolean lon = false;
    XContentBuilder json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).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("numeric value expected"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:GeoUtilsTests.java

示例14: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public final BucketMetricsPipelineAggregationBuilder<?> parse(String pipelineAggregatorName, QueryParseContext context)
        throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token;
    String currentFieldName = null;
    String[] bucketsPaths = null;
    String format = null;
    GapPolicy gapPolicy = null;
    Map<String, Object> params = new HashMap<>(5);

    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (FORMAT.match(currentFieldName)) {
                format = parser.text();
            } else if (BUCKETS_PATH.match(currentFieldName)) {
                bucketsPaths = new String[] { parser.text() };
            } else if (GAP_POLICY.match(currentFieldName)) {
                gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
            } else {
                parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (BUCKETS_PATH.match(currentFieldName)) {
                List<String> paths = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    String path = parser.text();
                    paths.add(path);
                }
                bucketsPaths = paths.toArray(new String[paths.size()]);
            } else {
                parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
            }
        } else {
            parseToken(pipelineAggregatorName, parser, context, currentFieldName, token, params);
        }
    }

    if (bucketsPaths == null) {
        throw new ParsingException(parser.getTokenLocation(),
                "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for aggregation [" + pipelineAggregatorName + "]");
    }

    BucketMetricsPipelineAggregationBuilder<?> factory  = buildFactory(pipelineAggregatorName, bucketsPaths[0], params);
    if (format != null) {
        factory.format(format);
    }
    if (gapPolicy != null) {
        factory.gapPolicy(gapPolicy);
    }

    assert(factory != null);

    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:58,代码来源:BucketMetricsParser.java

示例15: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public final PipelineAggregatorFactory parse(String pipelineAggregatorName, XContentParser parser, SearchContext context) throws IOException {
    XContentParser.Token token;
    String currentFieldName = null;
    String[] bucketsPaths = null;
    String format = null;
    GapPolicy gapPolicy = GapPolicy.SKIP;
    Map<String, Object> leftover = new HashMap<>(5);

    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) {
                format = parser.text();
            } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
                bucketsPaths = new String[] { parser.text() };
            } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
                gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
            } else {
                leftover.put(currentFieldName, parser.text());
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
                List<String> paths = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    String path = parser.text();
                    paths.add(path);
                }
                bucketsPaths = paths.toArray(new String[paths.size()]);
            } else {
                leftover.put(currentFieldName, parser.list());
            }
        } else {
            leftover.put(currentFieldName, parser.objectText());
        }
    }

    if (bucketsPaths == null) {
        throw new SearchParseException(context, "Missing required field [" + BUCKETS_PATH.getPreferredName()
                + "] for aggregation [" + pipelineAggregatorName + "]", parser.getTokenLocation());
    }

    ValueFormatter formatter = null;
    if (format != null) {
        formatter = ValueFormat.Patternable.Number.format(format).formatter();
    } else {
        formatter = ValueFormatter.RAW;
    }

    PipelineAggregatorFactory factory = null;
    try {
        factory = buildFactory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter, leftover);
    } catch (ParseException exception) {
        throw new SearchParseException(context, "Could not parse settings for aggregation ["
                + pipelineAggregatorName + "].", null, exception);
    }

    if (leftover.size() > 0) {
        throw new SearchParseException(context, "Unexpected tokens " + leftover.keySet() + " in [" + pipelineAggregatorName + "].", null);
    }
    assert(factory != null);

    return factory;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:66,代码来源:BucketMetricsParser.java


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