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


Java IndexRequest.id方法代码示例

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


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

示例1: shardIndexOperation

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
private WriteResult<IndexResponse> shardIndexOperation(BulkShardRequest request, IndexRequest indexRequest, MetaData metaData,
                                        IndexShard indexShard, boolean processed) throws Throwable {
    indexShard.checkDiskSpace(fsService);
    // validate, if routing is required, that we got routing
    MappingMetaData mappingMd = metaData.index(request.index()).mappingOrDefault(indexRequest.type());
    if (mappingMd != null && mappingMd.routing().required()) {
        if (indexRequest.routing() == null) {
            throw new RoutingMissingException(request.index(), indexRequest.type(), indexRequest.id());
        }
    }

    if (!processed) {
        indexRequest.process(metaData, mappingMd, allowIdGeneration, request.index());
    }

    return TransportIndexAction.executeIndexRequestOnPrimary(request, indexRequest, indexShard, mappingUpdatedAction);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportShardBulkAction.java

示例2: buildRequest

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
@Override
protected RequestWrapper<IndexRequest> buildRequest(ScrollableHitSource.Hit doc) {
    IndexRequest index = new IndexRequest();
    index.index(doc.getIndex());
    index.type(doc.getType());
    index.id(doc.getId());
    index.source(doc.getSource(), doc.getXContentType());
    index.versionType(VersionType.INTERNAL);
    index.version(doc.getVersion());
    index.setPipeline(mainRequest.getPipeline());
    return wrap(index);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TransportUpdateByQueryAction.java

示例3: innerExecute

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
private void innerExecute(IndexRequest indexRequest, Pipeline pipeline) throws Exception {
    if (pipeline.getProcessors().isEmpty()) {
        return;
    }

    long startTimeInNanos = System.nanoTime();
    // the pipeline specific stat holder may not exist and that is fine:
    // (e.g. the pipeline may have been removed while we're ingesting a document
    Optional<StatsHolder> pipelineStats = Optional.ofNullable(statsHolderPerPipeline.get(pipeline.getId()));
    try {
        totalStats.preIngest();
        pipelineStats.ifPresent(StatsHolder::preIngest);
        String index = indexRequest.index();
        String type = indexRequest.type();
        String id = indexRequest.id();
        String routing = indexRequest.routing();
        String parent = indexRequest.parent();
        Map<String, Object> sourceAsMap = indexRequest.sourceAsMap();
        IngestDocument ingestDocument = new IngestDocument(index, type, id, routing, parent, sourceAsMap);
        pipeline.execute(ingestDocument);

        Map<IngestDocument.MetaData, String> metadataMap = ingestDocument.extractMetadata();
        //it's fine to set all metadata fields all the time, as ingest document holds their starting values
        //before ingestion, which might also get modified during ingestion.
        indexRequest.index(metadataMap.get(IngestDocument.MetaData.INDEX));
        indexRequest.type(metadataMap.get(IngestDocument.MetaData.TYPE));
        indexRequest.id(metadataMap.get(IngestDocument.MetaData.ID));
        indexRequest.routing(metadataMap.get(IngestDocument.MetaData.ROUTING));
        indexRequest.parent(metadataMap.get(IngestDocument.MetaData.PARENT));
        indexRequest.source(ingestDocument.getSourceAndMetadata());
    } catch (Exception e) {
        totalStats.ingestFailed();
        pipelineStats.ifPresent(StatsHolder::ingestFailed);
        throw e;
    } finally {
        long ingestTimeInMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeInNanos);
        totalStats.postIngest(ingestTimeInMillis);
        pipelineStats.ifPresent(statsHolder -> statsHolder.postIngest(ingestTimeInMillis));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:PipelineExecutionService.java

示例4: executeIndexRequest

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
private static BulkItemResultHolder executeIndexRequest(final IndexRequest indexRequest,
                                                        final BulkItemRequest bulkItemRequest,
                                                        final IndexShard primary,
                                                        final MappingUpdatePerformer mappingUpdater) throws Exception {
    Engine.IndexResult indexResult = executeIndexRequestOnPrimary(indexRequest, primary, mappingUpdater);
    if (indexResult.hasFailure()) {
        return new BulkItemResultHolder(null, indexResult, bulkItemRequest);
    } else {
        IndexResponse response = new IndexResponse(primary.shardId(), indexRequest.type(), indexRequest.id(),
                indexResult.getSeqNo(), indexResult.getVersion(), indexResult.isCreated());
        return new BulkItemResultHolder(response, indexResult, bulkItemRequest);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TransportShardBulkAction.java

示例5: markCurrentItemAsFailed

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
void markCurrentItemAsFailed(Exception e) {
    IndexRequest indexRequest = (IndexRequest) bulkRequest.requests().get(currentSlot);
    // We hit a error during preprocessing a request, so we:
    // 1) Remember the request item slot from the bulk, so that we're done processing all requests we know what failed
    // 2) Add a bulk item failure for this request
    // 3) Continue with the next request in the bulk.
    failedSlots.set(currentSlot);
    BulkItemResponse.Failure failure = new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), e);
    itemResponses.add(new BulkItemResponse(currentSlot, indexRequest.opType(), failure));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:TransportBulkAction.java

示例6: indexOnPrimary

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
/**
 * indexes the given requests on the supplied primary, modifying it for replicas
 */
protected IndexResponse indexOnPrimary(IndexRequest request, IndexShard primary) throws Exception {
    final Engine.IndexResult indexResult = executeIndexRequestOnPrimary(request, primary,
            new TransportShardBulkActionTests.NoopMappingUpdatePerformer());
    request.primaryTerm(primary.getPrimaryTerm());
    TransportWriteActionTestHelper.performPostWriteActions(primary, request, indexResult.getTranslogLocation(), logger);
    return new IndexResponse(
        primary.shardId(),
        request.type(),
        request.id(),
        indexResult.getSeqNo(),
        indexResult.getVersion(),
        indexResult.isCreated());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ESIndexLevelReplicationTestCase.java

示例7: afterBulk

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
        Throwable throwable) {
    eventCounter.scope("bulks_received").incrBy(1);
    LOG.error("Exception with bulk {} - failing the whole lot ",
            executionId, throwable);
    synchronized (waitAck) {
        // WHOLE BULK FAILED
        // mark all the docs as fail
        Iterator<ActionRequest> itreq = request.requests().iterator();
        while (itreq.hasNext()) {
            IndexRequest bir = (IndexRequest) itreq.next();
            String id = bir.id();
            List<Tuple> xx = waitAck.getIfPresent(id);
            if (xx != null) {
                LOG.debug("Failed {} tuple(s) for ID {}", xx.size(), id);
                for (Tuple x : xx) {
                    // fail it
                    _collector.fail(x);
                }
                waitAck.invalidate(id);
            } else {
                LOG.warn("Could not find unacked tuple for {}", id);
            }
        }
    }
}
 
开发者ID:eorliac,项目名称:patent-crawler,代码行数:28,代码来源:StatusUpdaterBolt.java

示例8: testIndex

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
public void testIndex() throws IOException {
    String index = randomAsciiOfLengthBetween(3, 10);
    String type = randomAsciiOfLengthBetween(3, 10);
    IndexRequest indexRequest = new IndexRequest(index, type);

    String id = randomBoolean() ? randomAsciiOfLengthBetween(3, 10) : null;
    indexRequest.id(id);

    Map<String, String> expectedParams = new HashMap<>();

    String method = "POST";
    if (id != null) {
        method = "PUT";
        if (randomBoolean()) {
            indexRequest.opType(DocWriteRequest.OpType.CREATE);
        }
    }

    setRandomTimeout(indexRequest, expectedParams);
    setRandomRefreshPolicy(indexRequest, expectedParams);

    // There is some logic around _create endpoint and version/version type
    if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) {
        indexRequest.version(randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED));
        expectedParams.put("version", Long.toString(Versions.MATCH_DELETED));
    } else {
        setRandomVersion(indexRequest, expectedParams);
        setRandomVersionType(indexRequest, expectedParams);
    }

    if (frequently()) {
        if (randomBoolean()) {
            String routing = randomAsciiOfLengthBetween(3, 10);
            indexRequest.routing(routing);
            expectedParams.put("routing", routing);
        }
        if (randomBoolean()) {
            String parent = randomAsciiOfLengthBetween(3, 10);
            indexRequest.parent(parent);
            expectedParams.put("parent", parent);
        }
        if (randomBoolean()) {
            String pipeline = randomAsciiOfLengthBetween(3, 10);
            indexRequest.setPipeline(pipeline);
            expectedParams.put("pipeline", pipeline);
        }
    }

    XContentType xContentType = randomFrom(XContentType.values());
    int nbFields = randomIntBetween(0, 10);
    try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
        builder.startObject();
        for (int i = 0; i < nbFields; i++) {
            builder.field("field_" + i, i);
        }
        builder.endObject();
        indexRequest.source(builder);
    }

    Request request = Request.index(indexRequest);
    if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) {
        assertEquals("/" + index + "/" + type + "/" + id + "/_create", request.endpoint);
    } else if (id != null) {
        assertEquals("/" + index + "/" + type + "/" + id, request.endpoint);
    } else {
        assertEquals("/" + index + "/" + type, request.endpoint);
    }
    assertEquals(expectedParams, request.params);
    assertEquals(method, request.method);

    HttpEntity entity = request.entity;
    assertNotNull(entity);
    assertTrue(entity instanceof ByteArrayEntity);

    try (XContentParser parser = createParser(xContentType.xContent(), entity.getContent())) {
        assertEquals(nbFields, parser.map().size());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:79,代码来源:RequestTests.java

示例9: testPipelineFailures

import org.elasticsearch.action.index.IndexRequest; //导入方法依赖的package包/类
public void testPipelineFailures() {
    BulkRequest originalBulkRequest = new BulkRequest();
    for (int i = 0; i < 32; i++) {
        originalBulkRequest.add(new IndexRequest("index", "type", String.valueOf(i)));
    }

    TransportBulkAction.BulkRequestModifier modifier = new TransportBulkAction.BulkRequestModifier(originalBulkRequest);
    for (int i = 0; modifier.hasNext(); i++) {
        modifier.next();
        if (i % 2 == 0) {
            modifier.markCurrentItemAsFailed(new RuntimeException());
        }
    }

    // So half of the requests have "failed", so only the successful requests are left:
    BulkRequest bulkRequest = modifier.getBulkRequest();
    assertThat(bulkRequest.requests().size(), Matchers.equalTo(16));

    List<BulkItemResponse> responses = new ArrayList<>();
    ActionListener<BulkResponse> bulkResponseListener = modifier.wrapActionListenerIfNeeded(1L, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse bulkItemResponses) {
            responses.addAll(Arrays.asList(bulkItemResponses.getItems()));
        }

        @Override
        public void onFailure(Exception e) {
        }
    });

    List<BulkItemResponse> originalResponses = new ArrayList<>();
    for (DocWriteRequest actionRequest : bulkRequest.requests()) {
        IndexRequest indexRequest = (IndexRequest) actionRequest;
        IndexResponse indexResponse = new IndexResponse(new ShardId("index", "_na_", 0), indexRequest.type(),
                                                           indexRequest.id(), 1, 1, true);
        originalResponses.add(new BulkItemResponse(Integer.parseInt(indexRequest.id()), indexRequest.opType(), indexResponse));
    }
    bulkResponseListener.onResponse(new BulkResponse(originalResponses.toArray(new BulkItemResponse[originalResponses.size()]), 0));

    assertThat(responses.size(), Matchers.equalTo(32));
    for (int i = 0; i < 32; i++) {
        assertThat(responses.get(i).getId(), Matchers.equalTo(String.valueOf(i)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:BulkRequestModifierTests.java


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