How to handle null pointer exceptions in elasticsearch

I use elasticsearch and I tried to handle the case when the database is empty

@SuppressWarnings("unchecked")
public <M extends Model> SearchResults<M> findPage(int page, String search, String searchFields, String orderBy, String order, String where) {
    BoolQueryBuilder qb = buildQueryBuilder(search, searchFields, where);           
    Query<M> query = (Query<M>) ElasticSearch.query(qb, entityClass);
    // FIXME Currently we ignore the orderBy and order fields
    query.from((page - 1) * getPageSize()).size(getPageSize());
    query.hydrate(true);
    return query.fetch();   
}

an error occurred while returning query.fetch ();

I am trying to implement a try and catch statement, but it does not work, can anyone help with this, please?

+3
source share

All Articles