Search in sources :

Example 96 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project samza by apache.

the class ElasticsearchSystemProducerTest method testFlushFailedSendFromFailedDocument.

@Test(expected = SamzaException.class)
public void testFlushFailedSendFromFailedDocument() throws Exception {
    ArgumentCaptor<BulkProcessor.Listener> listenerCaptor = ArgumentCaptor.forClass(BulkProcessor.Listener.class);
    when(BULK_PROCESSOR_FACTORY.getBulkProcessor(eq(CLIENT), listenerCaptor.capture())).thenReturn(processorOne);
    producer.register(SOURCE_ONE);
    BulkResponse response = getRespWithFailedDocument(RestStatus.BAD_REQUEST);
    listenerCaptor.getValue().afterBulk(0, null, response);
    producer.flush(SOURCE_ONE);
}
Also used : BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Test(org.junit.Test)

Example 97 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project bibot by alfintech.

the class ElasticPublisher method publishAnalytics.

@Override
public void publishAnalytics(List<Analytic> analytics) throws IOException {
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    for (Analytic analytic : analytics) {
        System.out.println(analytic);
        XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("currencyPair", analytic.getCurrencyPair().toString()).field("intervalVolume", BigDecimalUtil.toDouble(analytic.getIntervalVolume())).field("dayVolume", BigDecimalUtil.toDouble(analytic.getDayAverage())).field("percentageVolume", BigDecimalUtil.toDouble(analytic.getPercentageVolume())).field("percentageAllTimeHigh", BigDecimalUtil.toDouble(analytic.getPercentageAllTimeHigh())).field("date", analytic.getDate()).endObject();
        bulkRequest.add(client.prepareIndex("marketdataanalytic", "minutely", analytic.getCurrencyPair().toString() + analytic.getDate().getTime()).setSource(builder));
    }
    BulkResponse response = bulkRequest.get();
    LOG.debug(response.toString());
}
Also used : Analytic(io.altanalytics.domain.currency.Analytic) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 98 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project stash-codesearch-plugin by palantir.

the class RequestBuffer method flush.

public BulkResponse flush() {
    BulkResponse resp = null;
    if (bulkRequest.numberOfActions() > 0) {
        resp = bulkRequest.get();
        bulkRequest = client.prepareBulk();
    }
    return resp;
}
Also used : BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 99 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project flink by apache.

the class Elasticsearch6SinkBuilder method getBulkProcessorBuilderFactory.

@Override
protected BulkProcessorBuilderFactory getBulkProcessorBuilderFactory() {
    return new BulkProcessorBuilderFactory() {

        @Override
        public BulkProcessor.Builder apply(RestHighLevelClient client, BulkProcessorConfig bulkProcessorConfig, BulkProcessor.Listener listener) {
            BulkProcessor.Builder builder = BulkProcessor.builder(new // This cannot be inlined as a
            BulkRequestConsumerFactory() {

                // lambda because then
                // deserialization fails
                @Override
                public void accept(BulkRequest bulkRequest, ActionListener<BulkResponse> bulkResponseActionListener) {
                    client.bulkAsync(bulkRequest, bulkResponseActionListener);
                }
            }, listener);
            if (bulkProcessorConfig.getBulkFlushMaxActions() != -1) {
                builder.setBulkActions(bulkProcessorConfig.getBulkFlushMaxActions());
            }
            if (bulkProcessorConfig.getBulkFlushMaxMb() != -1) {
                builder.setBulkSize(new ByteSizeValue(bulkProcessorConfig.getBulkFlushMaxMb(), ByteSizeUnit.MB));
            }
            if (bulkProcessorConfig.getBulkFlushInterval() != -1) {
                builder.setFlushInterval(new TimeValue(bulkProcessorConfig.getBulkFlushInterval()));
            }
            BackoffPolicy backoffPolicy;
            final TimeValue backoffDelay = new TimeValue(bulkProcessorConfig.getBulkFlushBackOffDelay());
            final int maxRetryCount = bulkProcessorConfig.getBulkFlushBackoffRetries();
            switch(bulkProcessorConfig.getFlushBackoffType()) {
                case CONSTANT:
                    backoffPolicy = BackoffPolicy.constantBackoff(backoffDelay, maxRetryCount);
                    break;
                case EXPONENTIAL:
                    backoffPolicy = BackoffPolicy.exponentialBackoff(backoffDelay, maxRetryCount);
                    break;
                case NONE:
                    backoffPolicy = BackoffPolicy.noBackoff();
                    break;
                default:
                    throw new IllegalArgumentException("Received unknown backoff policy type " + bulkProcessorConfig.getFlushBackoffType());
            }
            builder.setBackoffPolicy(backoffPolicy);
            return builder;
        }
    };
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 100 with BulkResponse

use of org.elasticsearch.action.bulk.BulkResponse in project elasticsearch-suggest-plugin by spinscale.

the class AbstractSuggestTest method indexProducts.

private void indexProducts(List<Map<String, Object>> products, String index, String routing) throws Exception {
    long currentCount = getCurrentDocumentCount(index);
    BulkRequest bulkRequest = new BulkRequest();
    for (Map<String, Object> product : products) {
        IndexRequest indexRequest = new IndexRequest(index, "product", (String) product.get("ProductId"));
        indexRequest.source(product);
        if (Strings.hasLength(routing)) {
            indexRequest.routing(routing);
        }
        bulkRequest.add(indexRequest);
    }
    bulkRequest.refresh(true);
    BulkResponse response = client().bulk(bulkRequest).actionGet();
    if (response.hasFailures()) {
        fail("Error in creating products: " + response.buildFailureMessage());
    }
    assertDocumentCountAfterIndexing(index, products.size() + currentCount);
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Aggregations

BulkResponse (org.elasticsearch.action.bulk.BulkResponse)108 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)59 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)40 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)26 IOException (java.io.IOException)20 IndexRequest (org.elasticsearch.action.index.IndexRequest)19 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Map (java.util.Map)11 IndexResponse (org.elasticsearch.action.index.IndexResponse)10 Test (org.junit.Test)10 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 SearchHit (org.elasticsearch.search.SearchHit)9 ElasticsearchException (org.elasticsearch.ElasticsearchException)8 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)8 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)8 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)8 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)7