javaelasticsearchelasticsearch-jest

Jest sort results by name


I have a Person index in my ElasticSearch database i get all the persons via this method:

public List<Person> findAll() {
    SearchResult result = null;
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
    Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(PERSON_INDEX_NAME)
            .addType(PERSON_TYPE_NAME).build();
    try {
        result = client.execute(search);
    } catch (IOException e) {
    }
    List<SearchResult.Hit<Person, Void>> hits = result.getHits(Person.class);
    return hits.stream().map(this::getPerson).collect(Collectors.toList());
}

but i want to get the results sorted alphabetically by name (person has String id and String name) but i cant figure out how. any help is apreciated


Solution

  • well.

    i took the list given by ES and ordered it using the Collections sort method