use of io.openk9.entity.manager.model.index.EntityIndex in project openk9 by smclab.
the class EntityService method search.
public List<EntityIndex> search(long tenantId, QueryBuilder queryBuilder, int from, int size) {
SearchRequest searchRequest = new SearchRequest(tenantId + "-entity");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
searchSourceBuilder.size(from);
searchSourceBuilder.size(size);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse searchResponse = _restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
SearchHits hits = searchResponse.getHits();
List<EntityIndex> results = new ArrayList<>(hits.getHits().length);
for (SearchHit hit : hits.getHits()) {
String sourceAsString = hit.getSourceAsString();
JsonObject json = new JsonObject(sourceAsString);
EntityIndex entityIndex = json.mapTo(EntityIndex.class);
entityIndex.setScore(hit.getScore());
results.add(entityIndex);
}
return results;
} catch (Exception e) {
_logger.error(e.getMessage());
}
return List.of();
}
Aggregations