Search in sources :

Example 46 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch-graphite-plugin by spinscale.

the class GraphitePluginIntegrationTest method testThatIndexingResultsInMonitoring.

@Test
public void testThatIndexingResultsInMonitoring() throws Exception {
    node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
    IndexResponse indexResponse = indexElement(node, index, type, "value");
    assertThat(indexResponse.getId(), is(notNullValue()));
    Thread.sleep(2000);
    ensureValidKeyNames();
    assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing._all.indexCount 1");
    assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing." + type + ".indexCount 1");
    assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".indexes." + index + ".id.0.search._all.queryCount ");
    assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".node.jvm.threads.peakCount ");
    assertGraphiteMetricIsContained("^elasticsearch." + clusterName + ".node.search._all.queryCount ");
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) Test(org.junit.Test)

Example 47 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch-graphite-plugin by spinscale.

the class GraphitePluginIntegrationTest method masterFailOverShouldWork.

@Test
public void masterFailOverShouldWork() throws Exception {
    node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
    String clusterName = UUID.randomUUID().toString().replaceAll("-", "");
    IndexResponse indexResponse = indexElement(node, index, type, "value");
    assertThat(indexResponse.getId(), is(notNullValue()));
    Node origNode = node;
    node = createNode(clusterName, GRAPHITE_SERVER_PORT, "1s");
    graphiteMockServer.content.clear();
    origNode.stop();
    indexResponse = indexElement(node, index, type, "value");
    assertThat(indexResponse.getId(), is(notNullValue()));
    // wait for master fail over and writing to graph reporter
    Thread.sleep(2000);
    assertGraphiteMetricIsContained("elasticsearch." + clusterName + ".indexes." + index + ".id.0.indexing._all.indexCount 1");
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) NodeTestHelper.createNode(org.elasticsearch.module.graphite.test.NodeTestHelper.createNode) Node(org.elasticsearch.node.Node) Test(org.junit.Test)

Example 48 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project samza by apache.

the class ElasticsearchSystemProducer method register.

@Override
public void register(final String source) {
    BulkProcessor.Listener listener = new BulkProcessor.Listener() {

        @Override
        public void beforeBulk(long executionId, BulkRequest request) {
        // Nothing to do.
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
            boolean hasFatalError = false;
            // Do not consider version conficts to be errors. Ignore old versions
            if (response.hasFailures()) {
                for (BulkItemResponse itemResp : response.getItems()) {
                    if (itemResp.isFailed()) {
                        if (itemResp.getFailure().getStatus().equals(RestStatus.CONFLICT)) {
                            LOGGER.info("Failed to index document in Elasticsearch: " + itemResp.getFailureMessage());
                        } else {
                            hasFatalError = true;
                            LOGGER.error("Failed to index document in Elasticsearch: " + itemResp.getFailureMessage());
                        }
                    }
                }
            }
            if (hasFatalError) {
                sendFailed.set(true);
            } else {
                updateSuccessMetrics(response);
            }
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
            LOGGER.error(failure.getMessage());
            thrown.compareAndSet(null, failure);
            sendFailed.set(true);
        }

        private void updateSuccessMetrics(BulkResponse response) {
            metrics.bulkSendSuccess.inc();
            int writes = 0;
            for (BulkItemResponse itemResp : response.getItems()) {
                if (itemResp.isFailed()) {
                    if (itemResp.getFailure().getStatus().equals(RestStatus.CONFLICT)) {
                        metrics.conflicts.inc();
                    }
                } else {
                    ActionResponse resp = itemResp.getResponse();
                    if (resp instanceof IndexResponse) {
                        writes += 1;
                        if (((IndexResponse) resp).isCreated()) {
                            metrics.inserts.inc();
                        } else {
                            metrics.updates.inc();
                        }
                    } else {
                        LOGGER.error("Unexpected Elasticsearch action response type: " + resp.getClass().getSimpleName());
                    }
                }
            }
            LOGGER.info(String.format("Wrote %s messages from %s to %s.", writes, source, system));
        }
    };
    sourceBulkProcessor.put(source, bulkProcessorFactory.getBulkProcessor(client, listener));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ActionResponse(org.elasticsearch.action.ActionResponse)

Example 49 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project YCSB by brianfrankcooper.

the class ElasticsearchClient method update.

@Override
public Status update(final String table, final String key, final Map<String, ByteIterator> values) {
    try {
        final SearchResponse response = search(table, key);
        if (response.getHits().totalHits == 0) {
            return Status.NOT_FOUND;
        }
        final SearchHit hit = response.getHits().getAt(0);
        for (final Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
            hit.getSource().put(entry.getKey(), entry.getValue());
        }
        final IndexResponse indexResponse = client.prepareIndex(indexKey, table, hit.getId()).setSource(hit.getSource()).get();
        if (indexResponse.getResult() != DocWriteResponse.Result.UPDATED) {
            return Status.ERROR;
        }
        if (!isRefreshNeeded) {
            synchronized (this) {
                isRefreshNeeded = true;
            }
        }
        return Status.OK;
    } catch (final Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) IndexResponse(org.elasticsearch.action.index.IndexResponse) UnknownHostException(java.net.UnknownHostException) DBException(site.ycsb.DBException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 50 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project YCSB by brianfrankcooper.

the class ElasticsearchClient method insert.

@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
    try (XContentBuilder doc = jsonBuilder()) {
        doc.startObject();
        for (final Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
            doc.field(entry.getKey(), entry.getValue());
        }
        doc.field(KEY, key);
        doc.endObject();
        final IndexResponse indexResponse = client.prepareIndex(indexKey, table).setSource(doc).get();
        if (indexResponse.getResult() != DocWriteResponse.Result.CREATED) {
            return Status.ERROR;
        }
        if (!isRefreshNeeded) {
            synchronized (this) {
                isRefreshNeeded = true;
            }
        }
        return Status.OK;
    } catch (final Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) UnknownHostException(java.net.UnknownHostException) DBException(site.ycsb.DBException)

Aggregations

IndexResponse (org.elasticsearch.action.index.IndexResponse)103 Test (org.junit.Test)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 IOException (java.io.IOException)15 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)15 HashMap (java.util.HashMap)13 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)13 IndexRequest (org.elasticsearch.action.index.IndexRequest)13 ElasticsearchException (org.elasticsearch.ElasticsearchException)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)8 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)7 Settings (org.elasticsearch.common.settings.Settings)7 ArrayList (java.util.ArrayList)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)6 ExecutionException (java.util.concurrent.ExecutionException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)5