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


Java BulkRequest类代码示例

本文整理汇总了Java中org.elasticsearch.action.bulk.BulkRequest的典型用法代码示例。如果您正苦于以下问题:Java BulkRequest类的具体用法?Java BulkRequest怎么用?Java BulkRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setupTest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
@Override
public void setupTest(BackendListenerContext context) throws Exception {
    try {
        this.index        = context.getParameter(ES_INDEX);
        this.bulkSize     = Integer.parseInt(context.getParameter(ES_BULK_SIZE));
        this.timeoutMs = JMeterUtils.getPropDefault(ES_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
        this.buildNumber  = (JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER) != null 
                && JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER).trim() != "") 
                ? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER)) : 0;
        String host         = context.getParameter(ES_HOST);
        int port         = Integer.parseInt(context.getParameter(ES_PORT));
        this.client       = new RestHighLevelClient(
                    RestClient.builder(
                        new HttpHost(host, port, context.getParameter(ES_SCHEME, "http")))
                    .setRequestConfigCallback(requestConfigBuilder -> 
                         requestConfigBuilder
                                    .setConnectTimeout(5000)
                                    .setSocketTimeout((int)timeoutMs))
                    .setMaxRetryTimeoutMillis(60000));
        this.bulkRequest = new BulkRequest().timeout(TimeValue.timeValueMillis(timeoutMs));
        super.setupTest(context);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to setup connectivity to ES", e);
    }
}
 
开发者ID:delirius325,项目名称:jmeter-elasticsearch-backend-listener,代码行数:26,代码来源:ElasticsearchBackend.java

示例2: failureHandlerExecutesFailoverForEachBatchItemSeparately

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的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: failureHandlerExecutesFailoverForEachBatchItemSeparately

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的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

示例4: configReturnsACopyOfServerUrisList

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
@Test
public void configReturnsACopyOfServerUrisList() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    builder.withServerUris("http://localhost:9200;http://localhost:9201;http://localhost:9202");
    ClientObjectFactory<TransportClient, BulkRequest> config = builder.build();

    // when
    Collection<String> serverUrisList = config.getServerList();
    serverUrisList.add("test");

    // then
    assertNotEquals(serverUrisList.size(), config.getServerList().size());

}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:17,代码来源:BulkProcessorObjectFactoryTest.java

示例5: prepareRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    String fieldsParam = request.param("fields");
    String defaultPipeline = request.param("pipeline");
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
        request.getXContentType());

    // short circuit the call to the transport layer
    return channel -> {
        BulkRestBuilderListener listener = new BulkRestBuilderListener(channel, request);
        listener.onResponse(bulkRequest);
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestNoopBulkAction.java

示例6: prepareRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
    String fieldsParam = request.param("fields");
    if (fieldsParam != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
    }
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
    String defaultPipeline = request.param("pipeline");
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields,
        defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());

    return channel -> client.bulk(bulkRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestBulkAction.java

示例7: sendBulkRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
/**
 * Send a bulk request, handling retries.
 */
void sendBulkRequest(TimeValue thisBatchStartTime, BulkRequest request) {
    if (task.isCancelled()) {
        finishHim(null);
        return;
    }
    bulkRetry.withAsyncBackoff(client, request, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse response) {
            onBulkResponse(thisBatchStartTime, response);
        }

        @Override
        public void onFailure(Exception e) {
            finishHim(e);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractAsyncBulkByScrollAction.java

示例8: testBulkRequestExecution

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
public void testBulkRequestExecution() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    String pipelineId = "_id";

    int numRequest = scaledRandomIntBetween(8, 64);
    for (int i = 0; i < numRequest; i++) {
        IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId);
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
        bulkRequest.add(indexRequest);
    }

    when(store.get(pipelineId)).thenReturn(new Pipeline(pipelineId, null, version, new CompoundProcessor()));

    @SuppressWarnings("unchecked")
    BiConsumer<IndexRequest, Exception> requestItemErrorHandler = mock(BiConsumer.class);
    @SuppressWarnings("unchecked")
    Consumer<Exception> completionHandler = mock(Consumer.class);
    executionService.executeBulkRequest(bulkRequest.requests(), requestItemErrorHandler, completionHandler);

    verify(requestItemErrorHandler, never()).accept(any(), any());
    verify(completionHandler, times(1)).accept(null);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PipelineExecutionServiceTests.java

示例9: testDynamicDisabled

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
public void testDynamicDisabled() {
    IndexRequest request = new IndexRequest("index", "type", "1");
    request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(request);
    final AtomicBoolean onFailureCalled = new AtomicBoolean();

    transportBulkAction.execute(bulkRequest, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse bulkResponse) {
            fail("onResponse shouldn't be called");
        }

        @Override
        public void onFailure(Exception e) {
            onFailureCalled.set(true);
            assertThat(e, instanceOf(IndexNotFoundException.class));
            assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
        }
    });

    assertTrue(onFailureCalled.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DynamicMappingDisabledTests.java

示例10: bulkDelete

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
public String bulkDelete(String index,String type,String... ids){
	try {
		if(xclient==null){
			init();
		}
		BulkRequest request = new BulkRequest();
		for (String id : ids) {
			request.add(new DeleteRequest(index, type, id));
		}
		BulkResponse result = xclient.bulk(request);
		return result.toString();
	}catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:18,代码来源:ElasticsearchHighRestFactory.java

示例11: handleSampleResults

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的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

示例12: getClassType

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
public static <Request extends ActionRequest> short getClassType(final Request request) {
    if (DeleteRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_DELETE;
    } else if (DeleteByQueryRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_DELETE_BY_QUERY;
    } else if (IndexRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_INDEX;
    } else if (UpdateRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_UPDATE;
    } else if (UpdateByQueryRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_UPDATE_BY_QUERY;
    } else if (BulkRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_BULK;
    }
    return 0;
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:17,代码来源:RequestUtils.java

示例13: newRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <Request extends ActionRequest> Request newRequest(final short classType) {
    switch (classType) {
    case RequestUtils.TYPE_DELETE:
        return (Request) new DeleteRequest();
    case RequestUtils.TYPE_DELETE_BY_QUERY:
        return (Request) new DeleteByQueryRequest();
    case RequestUtils.TYPE_INDEX:
        return (Request) new IndexRequest();
    case RequestUtils.TYPE_UPDATE:
        return (Request) new UpdateRequest();
    case RequestUtils.TYPE_UPDATE_BY_QUERY:
        return (Request) new UpdateByQueryRequest();
    case RequestUtils.TYPE_BULK:
        return (Request) new BulkRequest();
    default:
        throw new ElasticsearchException("Unknown request type: " + classType);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:20,代码来源:RequestUtils.java

示例14: createBulkRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
public static BulkRequestBuilder createBulkRequest(final Client client, final StreamInput streamInput, final String index)
        throws IOException {
    final BulkRequestBuilder builder = client.prepareBulk();
    final BulkRequest request = builder.request();
    request.readFrom(streamInput);
    if (index != null) {
        request.requests().stream().forEach(req -> {
            if (req instanceof DeleteRequest) {
                ((DeleteRequest) req).index(index);
            } else if (req instanceof DeleteByQueryRequest) {
                ((DeleteByQueryRequest) req).indices(index);
            } else if (req instanceof IndexRequest) {
                ((IndexRequest) req).index(index);
            } else if (req instanceof UpdateRequest) {
                ((UpdateRequest) req).index(index);
            } else if (req instanceof UpdateByQueryRequest) {
                ((UpdateByQueryRequest) req).indices(index);
            } else {
                throw new ElasticsearchException("Unsupported request in bulk: " + req);
            }
        });
    }
    return builder;
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:25,代码来源:RequestUtils.java

示例15: purgeShards

import org.elasticsearch.action.bulk.BulkRequest; //导入依赖的package包/类
private void purgeShards(List<IndexShard> shardsToPurge) {
    for (IndexShard shardToPurge : shardsToPurge) {
        Query query = shardToPurge.indexService().mapperService().smartNameFieldType(TTLFieldMapper.NAME).rangeQuery(null, System.currentTimeMillis(), false, true);
        Engine.Searcher searcher = shardToPurge.acquireSearcher("indices_ttl");
        try {
            logger.debug("[{}][{}] purging shard", shardToPurge.routingEntry().index(), shardToPurge.routingEntry().id());
            ExpiredDocsCollector expiredDocsCollector = new ExpiredDocsCollector();
            searcher.searcher().search(query, expiredDocsCollector);
            List<DocToPurge> docsToPurge = expiredDocsCollector.getDocsToPurge();

            BulkRequest bulkRequest = new BulkRequest();
            for (DocToPurge docToPurge : docsToPurge) {

                bulkRequest.add(new DeleteRequest().index(shardToPurge.routingEntry().index()).type(docToPurge.type).id(docToPurge.id).version(docToPurge.version).routing(docToPurge.routing));
                bulkRequest = processBulkIfNeeded(bulkRequest, false);
            }
            processBulkIfNeeded(bulkRequest, true);
        } catch (Exception e) {
            logger.warn("failed to purge", e);
        } finally {
            searcher.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:IndicesTTLService.java


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