Search in sources :

Example 6 with ElasticException

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());
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) SearchHit(org.elasticsearch.search.SearchHit) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 7 with ElasticException

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());
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) ElasticException(io.hops.hopsworks.exceptions.ElasticException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) SearchHit(org.elasticsearch.search.SearchHit) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 8 with ElasticException

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;
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 9 with ElasticException

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);
    }
}
Also used : UpdateResponse(org.elasticsearch.action.update.UpdateResponse) ElasticException(io.hops.hopsworks.exceptions.ElasticException)

Example 10 with ElasticException

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;
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Aggregations

ElasticException (io.hops.hopsworks.exceptions.ElasticException)32 ServiceException (io.hops.hopsworks.exceptions.ServiceException)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)8 GenericException (io.hops.hopsworks.exceptions.GenericException)6 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)6 Project (io.hops.hopsworks.persistence.entity.project.Project)6 IOException (java.io.IOException)6 SearchHit (org.elasticsearch.search.SearchHit)6 ArrayList (java.util.ArrayList)5 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)5 Users (io.hops.hopsworks.persistence.entity.user.Users)4 Map (java.util.Map)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 Try (com.lambdista.util.Try)3 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)3 ElasticController (io.hops.hopsworks.common.elastic.ElasticController)3 ElasticFeaturestoreHit (io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit)3 FeaturestoreDocType (io.hops.hopsworks.common.elastic.FeaturestoreDocType)3 FeaturestoreXAttrsConstants (io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)3