當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexRequest類代碼示例

本文整理匯總了Java中org.elasticsearch.action.index.IndexRequest的典型用法代碼示例。如果您正苦於以下問題:Java IndexRequest類的具體用法?Java IndexRequest怎麽用?Java IndexRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IndexRequest類屬於org.elasticsearch.action.index包,在下文中一共展示了IndexRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: failureHandlerExecutesFailoverForEachBatchItemSeparately

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Test
public void failureHandlerExecutesFailoverForEachBatchItemSeparately() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = builder.build();

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

    String payload1 = "test1";
    String payload2 = "test2";
    BulkRequest bulk = new BulkRequest()
            .add(spy(new IndexRequest().source(payload1)))
            .add(spy(new IndexRequest().source(payload2)));

    // when
    config.createFailureHandler(failoverPolicy).apply(bulk);

    // then
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(failoverPolicy, times(2)).deliver((String) captor.capture());

    assertTrue(captor.getAllValues().contains(payload1));
    assertTrue(captor.getAllValues().contains(payload2));
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:26,代碼來源:BulkProcessorObjectFactoryTest.java

示例2: failureHandlerExecutesFailoverForEachBatchItemSeparately

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Test
public void failureHandlerExecutesFailoverForEachBatchItemSeparately() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<TransportClient, BulkRequest> config = builder.build();

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());

    String payload1 = "test1";
    String payload2 = "test2";
    BulkRequest bulk = new BulkRequest()
            .add(spy(new IndexRequest().source(payload1, XContentType.CBOR)))
            .add(spy(new IndexRequest().source(payload2, XContentType.CBOR)));

    // when
    config.createFailureHandler(failoverPolicy).apply(bulk);

    // then
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(failoverPolicy, times(2)).deliver((String) captor.capture());

    assertTrue(captor.getAllValues().contains(payload1));
    assertTrue(captor.getAllValues().contains(payload2));
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:26,代碼來源:BulkProcessorObjectFactoryTest.java

示例3: process

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Override
  public void process(DeviceEvent element, RuntimeContext ctx, RequestIndexer indexer) {
  	Map<String, Object> json = new HashMap<>();
json.put("phoneNumber", element.getPhoneNumber());
json.put("bin", element.getBin());
json.put("bout", element.getBout());
json.put("timestamp", element.getTimestamp());

System.out.println(json);

      IndexRequest source = Requests.indexRequest()
              .index("flink-test")
              .type("flink-log")
              .source(json);
      
      indexer.add(source);
  }
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:18,代碼來源:FlinkESConnector.java

示例4: validateAgainstAliases

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
/**
 * Throws an ActionRequestValidationException if the request tries to index
 * back into the same index or into an index that points to two indexes.
 * This cannot be done during request validation because the cluster state
 * isn't available then. Package private for testing.
 */
static void validateAgainstAliases(SearchRequest source, IndexRequest destination, RemoteInfo remoteInfo,
                                     IndexNameExpressionResolver indexNameExpressionResolver, AutoCreateIndex autoCreateIndex,
                                     ClusterState clusterState) {
    if (remoteInfo != null) {
        return;
    }
    String target = destination.index();
    if (false == autoCreateIndex.shouldAutoCreate(target, clusterState)) {
        /*
         * If we're going to autocreate the index we don't need to resolve
         * it. This is the same sort of dance that TransportIndexRequest
         * uses to decide to autocreate the index.
         */
        target = indexNameExpressionResolver.concreteIndexNames(clusterState, destination)[0];
    }
    for (String sourceIndex : indexNameExpressionResolver.concreteIndexNames(clusterState, source)) {
        if (sourceIndex.equals(target)) {
            ActionRequestValidationException e = new ActionRequestValidationException();
            e.addValidationError("reindex cannot write into an index its reading from [" + target + ']');
            throw e;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:TransportReindexAction.java

示例5: handleSampleResults

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Override
public void handleSampleResults(List<SampleResult> results, BackendListenerContext context) {
    for(SampleResult sr : results) {
        this.bulkRequest.add(
                new IndexRequest(this.index, "SampleResult").source(this.getElasticData(sr, context), 
                        XContentType.JSON));
    }

    if(this.bulkRequest.numberOfActions() >= this.bulkSize) {
        try {
            sendRequest(bulkRequest);
        } catch (Exception e) {
            logger.error("Error sending data to ES, data will be lost", e);
        } finally {
            this.bulkRequest = new BulkRequest().timeout(TimeValue.timeValueMillis(timeoutMs));
        }
    }
}
 
開發者ID:delirius325,項目名稱:jmeter-elasticsearch-backend-listener,代碼行數:19,代碼來源:ElasticsearchBackend.java

示例6: enforceSameContentType

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
/**
 * Ensure that the {@link IndexRequest}'s content type is supported by the Bulk API and that it conforms
 * to the current {@link BulkRequest}'s content type (if it's known at the time of this method get called).
 *
 * @return the {@link IndexRequest}'s content type
 */
static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
    XContentType requestContentType = indexRequest.getContentType();
    if (requestContentType != XContentType.JSON && requestContentType != XContentType.SMILE) {
        throw new IllegalArgumentException("Unsupported content-type found for request with content-type [" + requestContentType
                + "], only JSON and SMILE are supported");
    }
    if (xContentType == null) {
        return requestContentType;
    }
    if (requestContentType != xContentType) {
        throw new IllegalArgumentException("Mismatching content-type found for request with content-type [" + requestContentType
                + "], previous requests have content-type [" + xContentType + "]");
    }
    return xContentType;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:Request.java

示例7: indexDoc

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
protected Engine.Index indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType) throws IOException {
    final Engine.Index index;
    if (shard.routingEntry().primary()) {
        index = shard.prepareIndexOnPrimary(
            SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
                xContentType),
            Versions.MATCH_ANY,
            VersionType.INTERNAL,
            IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP,
            false);
    } else {
        index = shard.prepareIndexOnReplica(
            SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
                xContentType),
            randomInt(1 << 10), 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
    }
    shard.index(index);
    return index;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:IndexShardTestCase.java

示例8: prepareRequest

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"));
    indexRequest.routing(request.param("routing"));
    indexRequest.parent(request.param("parent"));
    indexRequest.setPipeline(request.param("pipeline"));
    indexRequest.source(request.content(), request.getXContentType());
    indexRequest.timeout(request.paramAsTime("timeout", IndexRequest.DEFAULT_TIMEOUT));
    indexRequest.setRefreshPolicy(request.param("refresh"));
    indexRequest.version(RestActions.parseVersion(request));
    indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType()));
    String sOpType = request.param("op_type");
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        indexRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    if (sOpType != null) {
        indexRequest.opType(sOpType);
    }

    return channel ->
            client.index(indexRequest, new RestStatusToXContentListener<>(channel, r -> r.getLocation(indexRequest.routing())));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:RestIndexAction.java

示例9: writeTo

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(consistencyLevel.id());
    out.writeVInt(requests.size());
    for (ActionRequest request : requests) {
        if (request instanceof IndexRequest) {
            out.writeByte((byte) 0);
        } else if (request instanceof DeleteRequest) {
            out.writeByte((byte) 1);
        } else if (request instanceof UpdateRequest) {
            out.writeByte((byte) 2);
        }
        request.writeTo(out);
    }
    out.writeBoolean(refresh);
    timeout.writeTo(out);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:19,代碼來源:BulkRequest.java

示例10: createWindowWordRanking

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
/**
 * Creates a new Elasticsearch request from the given element.
 * @param value the element to process.
 * @return the Elasticsearch request.
 */
private IndexRequest createWindowWordRanking(PlayerGridStatistics value) {
  String cellsJson = value.getStats().entrySet().stream()
      .map(e -> "{" + "\"cid\":\"" + e.getKey() + "\",\"presence\":" + e.getValue() + "}")
      .collect(Collectors.joining(","));
  String json =
      "{\"ts\":" + value.getTsStart() +
      ",\"pid\":" + value.getPid() +
      ",\"cells\":[" + cellsJson + "]}";

  //LOG.debug("JSON: {}", json);

  return Requests.indexRequest()
      .index(this.indexName)
      .type(this.typeName)
      .source(json);
}
 
開發者ID:braineering,項目名稱:socstream,代碼行數:22,代碼來源:PlayerGridStatisticsESSinkFunction.java

示例11: prepareIndexOnPrimary

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
private Engine.IndexingOperation prepareIndexOnPrimary(IndexShard indexShard,
                                                       long version,
                                                       ShardUpsertRequest request,
                                                       ShardUpsertRequest.Item item) {
    SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.PRIMARY, item.source())
            .type(request.type())
            .id(item.id())
            .routing(request.routing());

    if (logger.isTraceEnabled()) {
        logger.trace("[{}] shard operation with opType={} id={} version={}  source={}",
                indexShard.shardId(), item.opType(), item.id(), version, item.source().toUtf8());
    }
    if (item.opType() == IndexRequest.OpType.INDEX) {
        return indexShard.prepareIndexOnPrimary(sourceToParse, version, item.versionType(), request.canHaveDuplicates());
    }
    return indexShard.prepareCreateOnPrimary(
            sourceToParse, version, item.versionType(), request.canHaveDuplicates(), false);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:20,代碼來源:TransportShardUpsertAction.java

示例12: testNoopUpdateReplicaRequest

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
public void testNoopUpdateReplicaRequest() throws Exception {
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value");
    BulkItemRequest replicaRequest = new BulkItemRequest(0, writeRequest);

    DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "index", "id", 0, DocWriteResponse.Result.NOOP);
    BulkItemResultHolder noopResults = new BulkItemResultHolder(noopUpdateResponse, null, replicaRequest);

    Translog.Location location = new Translog.Location(0, 0, 0);
    BulkItemRequest[] items = new BulkItemRequest[0];
    BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
    Translog.Location newLocation = TransportShardBulkAction.updateReplicaRequest(noopResults,
            DocWriteRequest.OpType.UPDATE, location, bulkShardRequest);

    BulkItemResponse primaryResponse = replicaRequest.getPrimaryResponse();

    // Basically nothing changes in the request since it's a noop
    assertThat(newLocation, equalTo(location));
    assertThat(primaryResponse.getItemId(), equalTo(0));
    assertThat(primaryResponse.getId(), equalTo("id"));
    assertThat(primaryResponse.getOpType(), equalTo(DocWriteRequest.OpType.UPDATE));
    assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
    assertThat(primaryResponse.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:TransportShardBulkActionTests.java

示例13: executeIndexRequestOnReplica

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
/**
 * Execute the given {@link IndexRequest} on a replica shard, throwing a
 * {@link RetryOnReplicaException} if the operation needs to be re-tried.
 */
public static Engine.IndexResult executeIndexRequestOnReplica(DocWriteResponse primaryResponse, IndexRequest request, IndexShard replica) throws IOException {
    final ShardId shardId = replica.shardId();
    SourceToParse sourceToParse =
        SourceToParse.source(SourceToParse.Origin.REPLICA, shardId.getIndexName(), request.type(), request.id(), request.source(),
            request.getContentType()).routing(request.routing()).parent(request.parent());

    final Engine.Index operation;
    final long version = primaryResponse.getVersion();
    final VersionType versionType = request.versionType().versionTypeForReplicationAndRecovery();
    assert versionType.validateVersionForWrites(version);
    final long seqNo = primaryResponse.getSeqNo();
    try {
        operation = replica.prepareIndexOnReplica(sourceToParse, seqNo, version, versionType, request.getAutoGeneratedTimestamp(), request.isRetry());
    } catch (MapperParsingException e) {
        return new Engine.IndexResult(e, version, seqNo);
    }
    Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
    if (update != null) {
        throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update);
    }
    return replica.index(operation);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:TransportShardBulkAction.java

示例14: testBulkRequestWithRefresh

import org.elasticsearch.action.index.IndexRequest; //導入依賴的package包/類
public void testBulkRequestWithRefresh() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    // We force here a "id is missing" validation error
    bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    // We force here a "type is missing" validation error
    bulkRequest.add(new DeleteRequest("index", null, "id"));
    bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains(
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "id is missing",
            "type is missing",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:BulkRequestTests.java

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


注:本文中的org.elasticsearch.action.index.IndexRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。