SpringBoot 集成 ElasticSearch

@Repository
public interface SwingCardRecordRepository extends ElasticsearchRepository<SwingCardRecordBean, String> {

}

 

    @Autowired
    private SwingCardRecordRepository swingCardRecordRepository;

 

Pageable pageable = PageRequest.of(0, 10)

BoolQueryBuilder bqb = QueryBuilders.boolQuery();
bqb.must(QueryBuilders.matchPhraseQuery("projectId", labourWorkerModel.getProjectId()));
bqb.must(QueryBuilders.matchPhraseQuery("userId", labourWorkerModel.getId()));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
bqb.must(QueryBuilders.matchPhraseQuery("recordTime", df.format(Long.valueOf(attendanceQsdDto.getScandatetime()))));
SearchQuery query = new NativeSearchQueryBuilder()
      .withQuery(bqb)
      .withPageable(pageable)
      .build();
Page<SwingCardRecordBean> cardRecordModelPage = swingCardRecordRepository.search(query);

 

 // 模糊查询
    boolQueryBuilder.filter(QueryBuilders.wildcardQuery("itemDesc", "*手机*"));
    // 范围查询 from:相当于闭区间; gt:相当于开区间(>) gte:相当于闭区间 (>=) lt:开区间(<) lte:闭区间 (<=)
    boolQueryBuilder.filter(QueryBuilders.rangeQuery("itemPrice").from(4500).to(8899));
    sourceBuilder.query(boolQueryBuilder);

 

posted @ 2021-01-30 14:13  介寒食  阅读(100)  评论(0编辑  收藏  举报