Search in sources :

Example 1 with EsDatastoreException

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException in project kapua by eclipse.

the class AbstractStorableQueryConverter method toSearchRequestBuilder.

public SearchRequestBuilder toSearchRequestBuilder(String indices, String type, Q query) throws KapuaException, EsDatastoreException, UnknownHostException {
    if (query == null)
        throw new EsDatastoreException(String.format("Query parameter is undefined"));
    PredicateConverter pc = new PredicateConverter();
    SearchRequestBuilder searchReqBuilder = EsClient.getcurrent().prepareSearch(indices);
    searchReqBuilder.setTypes(type).setQuery(pc.toElasticsearchQuery(query.getPredicate())).setFrom(query.getOffset()).setSize(query.getLimit());
    String[] includes = this.getIncludes(query.getFetchStyle());
    String[] excludes = this.getExcludes(query.getFetchStyle());
    if (includes != null || excludes != null)
        searchReqBuilder.setFetchSource(includes, excludes);
    if (this.getFields() != null && this.getFields().length > 0)
        searchReqBuilder.addFields(this.getFields());
    return searchReqBuilder;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) EsDatastoreException(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException) PredicateConverter(org.eclipse.kapua.service.datastore.internal.elasticsearch.PredicateConverter)

Example 2 with EsDatastoreException

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException in project kapua by eclipse.

the class AbstractStorableQueryConverter method toCountRequestBuilder.

public SearchRequestBuilder toCountRequestBuilder(String indices, String type, Q query) throws KapuaException, EsDatastoreException, UnknownHostException {
    if (query == null)
        throw new EsDatastoreException(String.format("Query parameter is undefined"));
    PredicateConverter pc = new PredicateConverter();
    SearchRequestBuilder searchReqBuilder = EsClient.getcurrent().prepareSearch(indices);
    searchReqBuilder.setTypes(type).setQuery(pc.toElasticsearchQuery(query.getPredicate())).setSize(0);
    return searchReqBuilder;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) EsDatastoreException(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException) PredicateConverter(org.eclipse.kapua.service.datastore.internal.elasticsearch.PredicateConverter)

Aggregations

EsDatastoreException (org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException)2 PredicateConverter (org.eclipse.kapua.service.datastore.internal.elasticsearch.PredicateConverter)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2