easy-es/docs/en/sort.md
2022-03-17 11:01:44 +08:00

885 B

For field sorting, ascending sorting and descending sorting are supported:

wrapper.orderByDesc(Sort fields, support multiple fields)
wrapper.orderByAsc(Sort fields, support multiple fields)

Example of use:

    @Test
    public void testSort(){
        // To test the sorting, we added a creation time field to the Document object, updated the index, and added two pieces of data
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.like(Document::getContent,"Hello");
        wrapper.select(Document::getTitle,Document::getGmtCreate);
        List<Document> before = documentMapper.selectList(wrapper);
        System.out.println("before:"+before);
        wrapper.orderByDesc(Document::getGmtCreate);
        List<Document> desc = documentMapper.selectList(wrapper);
        System.out.println("desc:"+desc);
    }