BIGE_BIGGER
BIGE_BIGGER
采纳率10%
2018-11-30 07:33 浏览 10.3k

elasticsearch搜索 多条件排序

20

// 方式一
// List sortList = new ArrayList<>();
// sortList.add(new Sort.Order(Sort.Direction.ASC,"gradeNumber"));
// sortList.add(new Sort.Order(Sort.Direction.ASC,"studentSex"));
// sortList.add(new Sort.Order(Sort.Direction.ASC,"studentName"));
// Sort sort =new Sort(sortList);
PageRequest pageable = PageRequest.of(requestVO.getPageNumber(),requestVO.getPageSize());
// Page resultPage = fitnessTestRecordEsRepository.search(qt.getQueryBuilder(), pageable);

    //*******************************************
    //ES 搜索时 多条件排序 方式二
    SortBuilder sortBuilder1 = SortBuilders.fieldSort("gradeNumber").order(SortOrder.ASC);
    SortBuilder sortBuilder2 = SortBuilders.fieldSort("studentSex").order(SortOrder.ASC);
    SortBuilder sortBuilder3 = SortBuilders.fieldSort("studentName").order(SortOrder.ASC);

    NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder().withQuery(qt.getQueryBuilder())
            .withPageable(pageable).withSort(sortBuilder1).withSort(sortBuilder2).withSort(sortBuilder3);
    SearchQuery searchQuery = builder.build();
    Page<EsFitnessTestRecordDO> resultPage = fitnessTestRecordEsRepository.search(searchQuery);

// //*******************************************


两种方式都失败,请问应该怎么写

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

相关推荐