use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticController method globalSearchHighLevel.
public SearchHit[] globalSearchHighLevel(String searchTerm) throws ServiceException, ElasticException {
// check if the index are up and running
if (!elasticClientCtrl.mngIndexExists(Settings.META_INDEX)) {
throw new ServiceException(RESTCodes.ServiceErrorCode.ELASTIC_INDEX_NOT_FOUND, Level.SEVERE, "index: " + Settings.META_INDEX);
}
LOG.log(Level.FINE, "Found elastic index, now executing the query.");
SearchResponse response = executeSearchQuery(globalSearchQuery(searchTerm.toLowerCase()));
if (response.status().getStatus() == 200) {
if (response.getHits().getHits().length > 0) {
return response.getHits().getHits();
}
return new SearchHit[0];
}
// elasticsearch rather than a bad query
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, "Error while executing query, code: " + response.status().getStatus());
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticController method datasetSearchHighLevel.
public SearchHit[] datasetSearchHighLevel(Integer projectId, String datasetName, String searchTerm) throws ServiceException, ElasticException {
// check if the indices are up and running
if (!elasticClientCtrl.mngIndexExists(Settings.META_INDEX)) {
throw new ServiceException(RESTCodes.ServiceErrorCode.ELASTIC_INDEX_NOT_FOUND, Level.SEVERE, "index: " + Settings.META_INDEX);
}
String dsName = datasetName;
Project project;
if (datasetName.contains(Settings.SHARED_FILE_SEPARATOR)) {
String[] sharedDS = datasetName.split(Settings.SHARED_FILE_SEPARATOR);
dsName = sharedDS[1];
project = projectFacade.findByName(sharedDS[0]);
} else {
project = projectFacade.find(projectId);
}
Dataset dataset = datasetController.getByProjectAndDsName(project, null, dsName);
final long datasetId = dataset.getInodeId();
SearchResponse response = executeSearchQuery(datasetSearchQuery(datasetId, searchTerm.toLowerCase()));
if (response.status().getStatus() == 200) {
if (response.getHits().getHits().length > 0) {
return response.getHits().getHits();
}
return new SearchHit[0];
}
// elasticsearch rather than a bad query
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, "Error while executing query, code: " + response.status().getStatus());
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticClientController method bulkUpdateDoc.
public BulkResponse bulkUpdateDoc(BulkRequest request) throws ElasticException {
FailableSupplier<BulkResponse> query = () -> client.getClient().bulk(request, RequestOptions.DEFAULT);
BulkResponse response = executeElasticQuery(query, "elastic bulk update doc", request.toString());
if (response.status().getStatus() != 200) {
String msg = "doc update - bad status response:" + response.status().getStatus();
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, msg);
}
return response;
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticClientController method updateDoc.
public void updateDoc(UpdateRequest request) throws ElasticException {
FailableSupplier<UpdateResponse> query = () -> client.getClient().update(request, RequestOptions.DEFAULT);
UpdateResponse response = executeElasticQuery(query, "elastic update doc", request.toString());
if (response.status().getStatus() != 200) {
String msg = "doc update - bad status response:" + response.status().getStatus();
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, msg);
}
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticClientController method baseSearch.
/**
* When using this method keep in mind that a single page is returned and it is the user's job to get all pages
* @param request
* @return
* @throws ElasticException
*/
public SearchResponse baseSearch(SearchRequest request) throws ElasticException {
FailableSupplier<SearchResponse> query = () -> client.getClient().search(request, RequestOptions.DEFAULT);
SearchResponse response = executeElasticQuery(query, "elastic basic search", request.toString());
if (response.status().getStatus() != 200) {
String msg = "searchBasic query - bad status response:" + response.status().getStatus();
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, msg);
}
return response;
}
Aggregations