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


Java XContentParser.close方法代码示例

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


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

示例1: extractRequestSpecificFieldsAndReturnSearchCompatibleParser

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
 * We can't send parseSearchRequest REST content that it doesn't support
 * so we will have to remove the content that is valid in addition to
 * what it supports from the content first. This is a temporary hack and
 * should get better when SearchRequest has full ObjectParser support
 * then we can delegate and stuff.
 */
private XContentParser extractRequestSpecificFieldsAndReturnSearchCompatibleParser(XContentParser parser,
                                  Map<String, Consumer<Object>> bodyConsumers) throws IOException {
    if (parser == null) {
        return parser;
    }
    try {
        Map<String, Object> body = parser.map();

        for (Map.Entry<String, Consumer<Object>> consumer : bodyConsumers.entrySet()) {
            Object value = body.remove(consumer.getKey());
            if (value != null) {
                consumer.getValue().accept(value);
            }
        }

        try (XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType())) {
            return parser.contentType().xContent().createParser(parser.getXContentRegistry(), builder.map(body).bytes());
        }
    } finally {
        parser.close();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:AbstractBulkByQueryRestHandler.java

示例2: parseSource

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public void parseSource(BytesReference source) throws SQLParseException {
    XContentParser parser = null;
    try {
        if (source != null && source.length() != 0) {
            parser = XContentFactory.xContent(source).createParser(source);
            parse(parser);
        }
        validate();
    } catch (Exception e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        throw new SQLParseException("Failed to parse source [" + sSource + "]", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:SQLXContentSourceParser.java

示例3: parseFetchedDoc

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private ParsedDocument parseFetchedDoc(PercolateContext context, BytesReference fetchedDoc, IndexService documentIndexService, String index, String type) {
    ParsedDocument doc = null;
    XContentParser parser = null;
    try {
        parser = XContentFactory.xContent(fetchedDoc).createParser(fetchedDoc);
        MapperService mapperService = documentIndexService.mapperService();
        DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
        doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(type).flyweight(true));

        if (context.highlight() != null) {
            doc.setSource(fetchedDoc);
        }
    } catch (Throwable e) {
        throw new ElasticsearchParseException("failed to parse request", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }

    if (doc == null) {
        throw new ElasticsearchParseException("No doc to percolate in the request");
    }

    return doc;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:PercolatorService.java

示例4: parseSignificanceHeuristic

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private SignificanceHeuristic parseSignificanceHeuristic(
        ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry,
        XContentParser stParser) throws IOException {
    QueryParseContext parseContext = new QueryParseContext(stParser);
    stParser.nextToken();
    SignificantTermsAggregationBuilder aggregatorFactory =
            (SignificantTermsAggregationBuilder) SignificantTermsAggregationBuilder.getParser(
            significanceHeuristicParserRegistry).parse("testagg", parseContext);
    stParser.nextToken();
    assertThat(aggregatorFactory.getBucketCountThresholds().getMinDocCount(), equalTo(200L));
    assertThat(stParser.currentToken(), equalTo(null));
    stParser.close();
    return aggregatorFactory.significanceHeuristic();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:SignificanceHeuristicTests.java

示例5: addComplexField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static void addComplexField(XContentBuilder builder, String fieldName,
    XContentType contentType, byte[] data) throws IOException {
  XContentParser parser = null;
  try {
    // Elasticsearch will accept JSON directly but we need to validate that
    // the incoming event is JSON first. Sadly, the elasticsearch JSON parser
    // is a stream parser so we need to instantiate it, parse the event to
    // validate it, then instantiate it again to provide the JSON to
    // elasticsearch.
    // If validation fails then the incoming event is submitted to
    // elasticsearch as plain text.
    parser = XContentFactory.xContent(contentType).createParser(data);
    while (parser.nextToken() != null) {};

    // If the JSON is valid then include it
    parser = XContentFactory.xContent(contentType).createParser(data);
    // Add the field name, but not the value.
    builder.field(fieldName);
    // This will add the whole parsed content as the value of the field.
    builder.copyCurrentStructure(parser);
  } catch (JsonParseException ex) {
    // If we get an exception here the most likely cause is nested JSON that
    // can't be figured out in the body. At this point just push it through
    // as is
    addSimpleField(builder, fieldName, data);
  } finally {
    if (parser != null) {
      parser.close();
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:32,代码来源:ContentBuilderUtil.java

示例6: fetch

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
 * Fetches the Shape with the given ID in the given type and index.
 *
 * @param getRequest GetRequest containing index, type and id
 * @param path      Name or path of the field in the Shape Document where the Shape itself is located
 * @return Shape with the given ID
 * @throws IOException Can be thrown while parsing the Shape Document and extracting the Shape
 */
public ShapeBuilder fetch(GetRequest getRequest,String path) throws IOException {
    getRequest.preference("_local");
    getRequest.operationThreaded(false);
    GetResponse response = client.get(getRequest).actionGet();
    if (!response.isExists()) {
        throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found");
    }

    String[] pathElements = Strings.splitStringToArray(path, '.');
    int currentPathSlot = 0;

    XContentParser parser = null;
    try {
        parser = XContentHelper.createParser(response.getSourceAsBytesRef());
        XContentParser.Token currentToken;
        while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (currentToken == XContentParser.Token.FIELD_NAME) {
                if (pathElements[currentPathSlot].equals(parser.currentName())) {
                    parser.nextToken();
                    if (++currentPathSlot == pathElements.length) {
                        return ShapeBuilder.parse(parser);
                    }
                } else {
                    parser.nextToken();
                    parser.skipChildren();
                }
            }
        }
        throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:44,代码来源:ShapeFetchService.java

示例7: validateAliasFilter

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private void validateAliasFilter(XContentParser parser, IndexQueryParserService indexQueryParserService) throws IOException {
    QueryParseContext context = indexQueryParserService.getParseContext();
    try {
        context.reset(parser);
        context.parseInnerFilter();
    } finally {
        context.reset(null);
        parser.close();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:AliasValidator.java

示例8: shardOperation

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
protected ShardSuggestResponse shardOperation(ShardSuggestRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(request.shardId().id());
    ShardSuggestMetric suggestMetric = indexShard.getSuggestMetric();
    suggestMetric.preSuggest();
    long startTime = System.nanoTime();
    XContentParser parser = null;
    try (Engine.Searcher searcher = indexShard.acquireSearcher("suggest")) {
        BytesReference suggest = request.suggest();
        if (suggest != null && suggest.length() > 0) {
            parser = XContentFactory.xContent(suggest).createParser(suggest);
            if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
                throw new IllegalArgumentException("suggest content missing");
            }
            final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService(),
                    indexService.queryParserService(), request.shardId().getIndex(), request.shardId().id(), request);
            final Suggest result = suggestPhase.execute(context, searcher.searcher());
            return new ShardSuggestResponse(request.shardId(), result);
        }
        return new ShardSuggestResponse(request.shardId(), new Suggest());
    } catch (Throwable ex) {
        throw new ElasticsearchException("failed to execute suggest", ex);
    } finally {
        if (parser != null) {
            parser.close();
        }
        suggestMetric.postSuggest(System.nanoTime() - startTime);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:TransportSuggestAction.java

示例9: parseSource

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private void parseSource(SearchContext context, BytesReference source) throws SearchParseException {
    // nothing to parse...
    if (source == null || source.length() == 0) {
        return;
    }
    String abc = source.toUtf8();
    XContentParser parser = null;
    try {
        parser = XContentFactory.xContent(source).createParser(source);
        XContentParser.Token token;
        token = parser.nextToken();
        if (token != XContentParser.Token.START_OBJECT) {
            throw new ElasticsearchParseException("failed to parse search source. source must be an object, but found [{}] instead", token.name());
        }
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                String fieldName = parser.currentName();
                parser.nextToken();
                SearchParseElement element = elementParsers.get(fieldName);
                if (element == null) {
                    throw new SearchParseException(context, "failed to parse search source. unknown search element [" + fieldName + "]", parser.getTokenLocation());
                }
                element.parse(parser, context);
            } else {
                if (token == null) {
                    throw new ElasticsearchParseException("failed to parse search source. end of query source reached but query is not complete.");
                } else {
                    throw new ElasticsearchParseException("failed to parse search source. expected field name but got [{}]", token);
                }
            }
        }
    } catch (Throwable e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        XContentLocation location = parser != null ? parser.getTokenLocation() : null;
        throw new SearchParseException(context, "failed to parse search source [" + sSource + "]", location, e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:47,代码来源:SearchService.java


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