use of org.elasticsearch.index.IndexNotFoundException in project graylog2-server by Graylog2.
the class MongoIndexRangeServiceTest method testCalculateRangeWithNonExistingIndex.
@Test(expected = IndexNotFoundException.class)
public void testCalculateRangeWithNonExistingIndex() throws Exception {
when(indices.indexRangeStatsOfIndex("does-not-exist")).thenThrow(new IndexNotFoundException("does-not-exist"));
indexRangeService.calculateRange("does-not-exist");
}
use of org.elasticsearch.index.IndexNotFoundException in project camel by apache.
the class ElasticsearchProducer method process.
public void process(Exchange exchange) throws Exception {
// 2. Index and type will be set by:
// a. If the incoming body is already an action request
// b. If the body is not an action request we will use headers if they
// are set.
// c. If the body is not an action request and the headers aren't set we
// will use the configuration.
// No error is thrown by the component in the event none of the above
// conditions are met. The java es client
// will throw.
Message message = exchange.getIn();
final ElasticsearchOperation operation = resolveOperation(exchange);
// Set the index/type headers on the exchange if necessary. This is used
// for type conversion.
boolean configIndexName = false;
String indexName = message.getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, configuration.getIndexName());
configIndexName = true;
}
boolean configIndexType = false;
String indexType = message.getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, configuration.getIndexType());
configIndexType = true;
}
boolean configWaitForActiveShards = false;
Integer waitForActiveShards = message.getHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class);
if (waitForActiveShards == null) {
message.setHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, configuration.getWaitForActiveShards());
configWaitForActiveShards = true;
}
if (operation == ElasticsearchOperation.INDEX) {
IndexRequest indexRequest = message.getBody(IndexRequest.class);
message.setBody(client.index(indexRequest).actionGet().getId());
} else if (operation == ElasticsearchOperation.UPDATE) {
UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
message.setBody(client.update(updateRequest).actionGet().getId());
} else if (operation == ElasticsearchOperation.GET_BY_ID) {
GetRequest getRequest = message.getBody(GetRequest.class);
message.setBody(client.get(getRequest));
} else if (operation == ElasticsearchOperation.MULTIGET) {
MultiGetRequest multiGetRequest = message.getBody(MultiGetRequest.class);
message.setBody(client.multiGet(multiGetRequest));
} else if (operation == ElasticsearchOperation.BULK) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
message.setBody(client.bulk(bulkRequest).actionGet());
} else if (operation == ElasticsearchOperation.BULK_INDEX) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
List<String> indexedIds = new ArrayList<String>();
for (BulkItemResponse response : client.bulk(bulkRequest).actionGet().getItems()) {
indexedIds.add(response.getId());
}
message.setBody(indexedIds);
} else if (operation == ElasticsearchOperation.DELETE) {
DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
message.setBody(client.delete(deleteRequest).actionGet());
} else if (operation == ElasticsearchOperation.EXISTS) {
// ExistsRequest API is deprecated, using SearchRequest instead with size=0 and terminate_after=1
SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class));
try {
client.prepareSearch(searchRequest.indices()).setSize(0).setTerminateAfter(1).get();
message.setBody(true);
} catch (IndexNotFoundException e) {
message.setBody(false);
}
} else if (operation == ElasticsearchOperation.SEARCH) {
SearchRequest searchRequest = message.getBody(SearchRequest.class);
message.setBody(client.search(searchRequest).actionGet());
} else if (operation == ElasticsearchOperation.MULTISEARCH) {
MultiSearchRequest multiSearchRequest = message.getBody(MultiSearchRequest.class);
message.setBody(client.multiSearch(multiSearchRequest));
} else if (operation == ElasticsearchOperation.DELETE_INDEX) {
DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
message.setBody(client.admin().indices().delete(deleteIndexRequest).actionGet());
} else {
throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operation + "' is not supported");
}
// subsequent endpoint index/type with the first endpoint index/type.
if (configIndexName) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_NAME);
}
if (configIndexType) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_TYPE);
}
if (configWaitForActiveShards) {
message.removeHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS);
}
}
use of org.elasticsearch.index.IndexNotFoundException in project beam by apache.
the class ElasticSearchIOTestUtils method upgradeIndexAndGetCurrentNumDocs.
/**
* Forces an upgrade of the given index to make recently inserted documents available for search.
*
* @return The number of docs in the index
*/
static long upgradeIndexAndGetCurrentNumDocs(String index, String type, Client client) {
try {
client.admin().indices().upgrade(new UpgradeRequest(index)).actionGet();
SearchResponse response = client.prepareSearch(index).setTypes(type).execute().actionGet(5000);
return response.getHits().getTotalHits();
// it is fine to ignore bellow exceptions because in testWriteWithBatchSize* sometimes,
// we call upgrade before any doc have been written
// (when there are fewer docs processed than batchSize).
// In that cases index/type has not been created (created upon first doc insertion)
} catch (IndexNotFoundException e) {
} catch (java.lang.IllegalArgumentException e) {
if (!e.getMessage().contains("No search type")) {
throw e;
}
}
return 0;
}
use of org.elasticsearch.index.IndexNotFoundException in project components by Talend.
the class ElasticsearchTestUtils method upgradeIndexAndGetCurrentNumDocs.
/**
* Force an upgrade of all indices to make recently inserted documents available for search.
*
* @param client Elasticsearch TCP client to use for upgrade
* @return The number of docs in the index
*/
static long upgradeIndexAndGetCurrentNumDocs(String index, String type, Client client) {
try {
client.admin().indices().upgrade(new UpgradeRequest(index)).actionGet();
SearchResponse response = client.prepareSearch(index).setTypes(type).execute().actionGet(5000);
return response.getHits().getTotalHits();
// it is fine to ignore bellow exceptions because in testWriteWithBatchSize* sometimes,
// we call upgrade before any doc have been written
// (when there are fewer docs processed than batchSize).
// In that cases index/type has not been created (created upon first doc insertion)
} catch (IndexNotFoundException e) {
} catch (java.lang.IllegalArgumentException e) {
if (!e.getMessage().contains("No search type")) {
throw e;
}
}
return 0;
}
use of org.elasticsearch.index.IndexNotFoundException in project metron by apache.
the class ElasticsearchMetaAlertUpdateDao method update.
@Override
public Document update(Document update, Optional<String> index) throws IOException {
if (MetaAlertConstants.METAALERT_TYPE.equals(update.getSensorType())) {
// We've been passed an update to the meta alert.
throw new UnsupportedOperationException("Meta alerts cannot be directly updated");
} else {
Map<Document, Optional<String>> updates = new HashMap<>();
updates.put(update, index);
try {
// We need to update an alert itself. Only that portion of the update can be delegated.
// We still need to get meta alerts potentially associated with it and update.
SearchResponse response = getMetaAlertsForAlert(update.getGuid());
Collection<Document> metaAlerts = response.getResults().stream().map(result -> toDocument(result, update.getTimestamp())).collect(Collectors.toList());
// Each meta alert needs to be updated with the new alert
for (Document metaAlert : metaAlerts) {
replaceAlertInMetaAlert(metaAlert, update);
updates.put(metaAlert, Optional.of(METAALERTS_INDEX));
}
} catch (IndexNotFoundException e) {
List<String> indicesNotFound = e.getMetadata(INDEX_NOT_FOUND_INDICES_KEY);
// Otherwise throw the exception.
if (indicesNotFound.size() != 1 || !METAALERTS_INDEX.equals(indicesNotFound.get(0))) {
throw e;
}
}
// Run the alert's update
elasticsearchDao.batchUpdate(updates);
return update;
}
}
Aggregations