所以我用jest来练习elasticsearch 5.2 有这个:
@Override
public List<Aptitude> findAllAptitudes() {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(APTITUDE_INDEX_NAME).build();
try {
SearchResult result = JestClientUtils.getClient().execute(search);
List<Hit<Aptitude, Void>> aptitudes = result.getHits(Aptitude.class);
return aptitudes.stream().map(this::getAptitude).sorted(new Comparator<Aptitude>() {
@Override
public int compare(Aptitude o1, Aptitude o2) {
return o1.getId().compareTo(o2.getId());
}
}).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private Aptitude getAptitude(Hit<Aptitude, Void> hit) {
return hit.source;
}
但我想按 ID(来自 aptitude 的长属性)按顺序获得结果,但不知道如何去做。有人可以指出我正确的方向吗?提前致谢