springboot data jpa elasticsearch 随机排序

PageRequest pageRequest = PageRequest.of(newsPageRequest.getPage() - 1, newsPageRequest.getPageSize());
        // 分数、分页
        SearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withPageable(pageRequest)
                .withQuery(QueryBuilders.boolQuery().must(QueryBuilders.queryStringQuery(sb.toString())))
                .withSort(SortBuilders.scriptSort(new Script("Math.random()"), ScriptSortBuilder.ScriptSortType.NUMBER))
//                        .withQuery(QueryBuilders.matchQuery("isDelete",0))
                .build();
        Page<EsNews> esNewsPage = esNewsRepository.search(searchQuery);
       

(全文完)

(转载本站文章请注明作者和出处 springboot data jpa elasticsearch 随机排序