Search in sources :

Example 46 with IndexResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project fess-crawler by codelibs.

the class AbstractCrawlerService method insert.

protected IndexResponse insert(final Object target, final OpType opType) {
    final String id = getId(getSessionId(target), getUrl(target));
    final XContentBuilder source = getXContentBuilder(target);
    try {
        final IndexResponse response = getClient().get(c -> c.prepareIndex(index, type, id).setSource(source).setOpType(opType).setRefreshPolicy(RefreshPolicy.IMMEDIATE).execute());
        setId(target, id);
        return response;
    } catch (final Exception e) {
        throw new EsAccessException("Failed to insert " + id, e);
    }
}
Also used : CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) EsAccessException(org.codelibs.fess.crawler.exception.EsAccessException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ParseException(java.text.ParseException) EsAccessException(org.codelibs.fess.crawler.exception.EsAccessException) IOException(java.io.IOException)

Example 47 with IndexResponse

use of org.graylog.shaded.elasticsearch7.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 48 with IndexResponse

use of org.graylog.shaded.elasticsearch7.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 49 with IndexResponse

use of org.graylog.shaded.elasticsearch7.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 50 with IndexResponse

use of org.graylog.shaded.elasticsearch7.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)

Aggregations

IndexResponse (org.elasticsearch.action.index.IndexResponse)108 Test (org.junit.Test)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 IOException (java.io.IOException)17 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)17 IndexRequest (org.elasticsearch.action.index.IndexRequest)16 HashMap (java.util.HashMap)15 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)14 ElasticsearchException (org.elasticsearch.ElasticsearchException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)10 Settings (org.elasticsearch.common.settings.Settings)9 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)7 GetResponse (org.elasticsearch.action.get.GetResponse)7 ArrayList (java.util.ArrayList)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)6 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)6 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)6 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)6