Search in sources :

Example 16 with BulkItemResponse

use of org.elasticsearch.action.bulk.BulkItemResponse in project elasticsearch by elastic.

the class ShardInfoIT method testBulkWithIndexAndDeleteItems.

public void testBulkWithIndexAndDeleteItems() throws Exception {
    prepareIndex(1);
    BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
    for (int i = 0; i < 10; i++) {
        bulkRequestBuilder.add(client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
    }
    BulkResponse bulkResponse = bulkRequestBuilder.get();
    bulkRequestBuilder = client().prepareBulk();
    for (BulkItemResponse item : bulkResponse) {
        assertThat(item.isFailed(), equalTo(false));
        assertShardInfo(item.getResponse());
        bulkRequestBuilder.add(client().prepareDelete("idx", "type", item.getId()));
    }
    bulkResponse = bulkRequestBuilder.get();
    for (BulkItemResponse item : bulkResponse) {
        assertThat(item.isFailed(), equalTo(false));
        assertShardInfo(item.getResponse());
    }
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder)

Example 17 with BulkItemResponse

use of org.elasticsearch.action.bulk.BulkItemResponse in project elasticsearch by elastic.

the class ShardInfoIT method testBulkWithUpdateItems.

public void testBulkWithUpdateItems() throws Exception {
    prepareIndex(1);
    BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
    for (int i = 0; i < 10; i++) {
        bulkRequestBuilder.add(client().prepareUpdate("idx", "type", Integer.toString(i)).setDoc("{}", XContentType.JSON).setDocAsUpsert(true));
    }
    BulkResponse bulkResponse = bulkRequestBuilder.get();
    for (BulkItemResponse item : bulkResponse) {
        assertThat(item.isFailed(), equalTo(false));
        assertShardInfo(item.getResponse());
    }
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder)

Example 18 with BulkItemResponse

use of org.elasticsearch.action.bulk.BulkItemResponse in project elasticsearch by elastic.

the class CircuitBreakerServiceIT method testLimitsRequestSize.

public void testLimitsRequestSize() throws Exception {
    ByteSizeValue inFlightRequestsLimit = new ByteSizeValue(8, ByteSizeUnit.KB);
    if (noopBreakerUsed()) {
        logger.info("--> noop breakers used, skipping test");
        return;
    }
    internalCluster().ensureAtLeastNumDataNodes(2);
    NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get();
    List<NodeStats> dataNodeStats = new ArrayList<>();
    for (NodeStats stat : nodeStats.getNodes()) {
        if (stat.getNode().isDataNode()) {
            dataNodeStats.add(stat);
        }
    }
    assertThat(dataNodeStats.size(), greaterThanOrEqualTo(2));
    Collections.shuffle(dataNodeStats, random());
    // send bulk request from source node to target node later. The sole shard is bound to the target node.
    NodeStats targetNode = dataNodeStats.get(0);
    NodeStats sourceNode = dataNodeStats.get(1);
    assertAcked(prepareCreate("index").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put("index.routing.allocation.include._name", targetNode.getNode().getName()).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE)));
    Client client = client(sourceNode.getNode().getName());
    // we use the limit size as a (very) rough indication on how many requests we should sent to hit the limit
    int numRequests = inFlightRequestsLimit.bytesAsInt();
    BulkRequest bulkRequest = new BulkRequest();
    for (int i = 0; i < numRequests; i++) {
        IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i));
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "num", i);
        bulkRequest.add(indexRequest);
    }
    Settings limitSettings = Settings.builder().put(IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), inFlightRequestsLimit).build();
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(limitSettings));
    // can either fail directly with an exception or the response contains exceptions (depending on client)
    try {
        BulkResponse response = client.bulk(bulkRequest).actionGet();
        if (!response.hasFailures()) {
            fail("Should have thrown CircuitBreakingException");
        } else {
            // each item must have failed with CircuitBreakingException
            for (BulkItemResponse bulkItemResponse : response) {
                Throwable cause = ExceptionsHelper.unwrapCause(bulkItemResponse.getFailure().getCause());
                assertThat(cause, instanceOf(CircuitBreakingException.class));
                assertEquals(((CircuitBreakingException) cause).getByteLimit(), inFlightRequestsLimit.getBytes());
            }
        }
    } catch (CircuitBreakingException ex) {
        assertEquals(ex.getByteLimit(), inFlightRequestsLimit.getBytes());
    }
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) ArrayList(java.util.ArrayList) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndexRequest(org.elasticsearch.action.index.IndexRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings)

Example 19 with BulkItemResponse

use of org.elasticsearch.action.bulk.BulkItemResponse in project elasticsearch-river-couchdb by elastic.

the class CouchdbRiver method start.

@Override
public void start() {
    logger.info("starting couchdb stream: host [{}], port [{}], filter [{}], db [{}], indexing to [{}]/[{}]", couchHost, couchPort, couchFilter, couchDb, indexName, typeName);
    // Creating bulk processor
    this.bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() {

        @Override
        public void beforeBulk(long executionId, BulkRequest request) {
            logger.debug("Going to execute new bulk composed of {} actions", request.numberOfActions());
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
            logger.debug("Executed bulk composed of {} actions", request.numberOfActions());
            if (response.hasFailures()) {
                logger.warn("There was failures while executing bulk", response.buildFailureMessage());
                if (logger.isDebugEnabled()) {
                    for (BulkItemResponse item : response.getItems()) {
                        if (item.isFailed()) {
                            logger.debug("Error for {}/{}/{} for {} operation: {}", item.getIndex(), item.getType(), item.getId(), item.getOpType(), item.getFailureMessage());
                        }
                    }
                }
            }
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
            logger.warn("Error executing bulk", failure);
        }
    }).setBulkActions(bulkSize).setConcurrentRequests(maxConcurrentBulk).setFlushInterval(bulkFlushInterval).build();
    slurperThread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "couchdb_river_slurper").newThread(new Slurper());
    indexerThread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "couchdb_river_indexer").newThread(new Indexer());
    indexerThread.start();
    slurperThread.start();
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 20 with BulkItemResponse

use of org.elasticsearch.action.bulk.BulkItemResponse in project elasticsearch by elastic.

the class GeoFilterIT method testBulk.

public void testBulk() throws Exception {
    byte[] bulkAction = unZipData("/org/elasticsearch/search/geo/gzippedmap.gz");
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("country").startObject("properties").startObject("pin").field("type", "geo_point");
    xContentBuilder.field("store", true).endObject().startObject("location").field("type", "geo_shape").endObject().endObject().endObject().endObject();
    client().admin().indices().prepareCreate("countries").setSettings(settings).addMapping("country", xContentBuilder).execute().actionGet();
    BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, null, xContentBuilder.contentType()).get();
    for (BulkItemResponse item : bulk.getItems()) {
        assertFalse("unable to index data", item.isFailed());
    }
    client().admin().indices().prepareRefresh().execute().actionGet();
    String key = "DE";
    SearchResponse searchResponse = client().prepareSearch().setQuery(matchQuery("_id", key)).execute().actionGet();
    assertHitCount(searchResponse, 1);
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getId(), equalTo(key));
    }
    SearchResponse world = client().prepareSearch().addStoredField("pin").setQuery(geoBoundingBoxQuery("pin").setCorners(90, -179.99999, -90, 179.99999)).execute().actionGet();
    assertHitCount(world, 53);
    SearchResponse distance = client().prepareSearch().addStoredField("pin").setQuery(geoDistanceQuery("pin").distance("425km").point(51.11, 9.851)).execute().actionGet();
    assertHitCount(distance, 5);
    GeoPoint point = new GeoPoint();
    for (SearchHit hit : distance.getHits()) {
        String name = hit.getId();
        point.resetFromString(hit.getFields().get("pin").getValue());
        double dist = distance(point.getLat(), point.getLon(), 51.11, 9.851);
        assertThat("distance to '" + name + "'", dist, lessThanOrEqualTo(425000d));
        assertThat(name, anyOf(equalTo("CZ"), equalTo("DE"), equalTo("BE"), equalTo("NL"), equalTo("LU")));
        if (key.equals(name)) {
            assertThat(dist, closeTo(0d, 0.1d));
        }
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) SearchHit(org.elasticsearch.search.SearchHit) Version(org.elasticsearch.Version) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)29 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)24 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)13 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)8 IndexRequest (org.elasticsearch.action.index.IndexRequest)6 ArrayList (java.util.ArrayList)5 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)5 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)4 FailedNodeException (org.elasticsearch.action.FailedNodeException)4 Failure (org.elasticsearch.action.bulk.BulkItemResponse.Failure)4 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)4 UpdateRequestBuilder (org.elasticsearch.action.update.UpdateRequestBuilder)4 IOException (java.io.IOException)3 List (java.util.List)3 Entity (org.dbflute.Entity)3 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)3 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)3 SearchFailure (org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)3 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)3 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)3