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);
}
}
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 ");
}
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");
}
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));
}
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;
}
}
Aggregations