courseSearchParam ) { / / 设置索引 SearchRequest searchRequest = new SearchRequest ( es_index ) ; / / 设置类型 searchRequest. types ( es_type ) ; SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder ( ) ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery ( ) ; / / source源字段过虑 String[] source_fields = source_field.split ( "," ) ; searchSourceBuilder.fetchSource ( source_fields , new String[] { } ) ; / / 关键字 if ( StringUtils.isNotEmpty ( courseSearchParam.getKeyword ( ) ) ) { / / 匹配关键字 MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery ( courseSearchParam.getKeyword ( ) , "name" , "teachplan" , "description" ) ; / / 设置匹配占比 multiMatchQueryBuilder.minimumShouldMatch ( "70%" ) ; / / 提升另个字段的Boost值 multiMatchQueryBuilder.field ( "name" , 10 ) ; boolQueryBuilder.must ( multiMatchQueryBuilder ) ; } / / 布尔查询 searchSourceBuilder.query ( boolQueryBuilder ) ; / / 请求搜索 searchRequest.source ( searchSourceBuilder ) ; SearchResponse searchResponse = null; try { searchResponse = restHighLevelClient.search ( searchRequest ) ; } catch ( IOException e ) { e.printStackTrace ( ) ; LOGGER. error ( "xuecheng search error..{}" , e.getMessage ( ) ) ; return new QueryResponseResult ( CommonCode.SUCCESS , new QueryResult < CoursePub > ( ) ) ; } / / 结果集处理 SearchHits hits = searchResponse.getHits ( ) ; SearchHit[] searchHits = hits.getHits ( ) ; / / 记录总数 long totalHits = hits.getTotalHits ( ) ; / / 数据列表 List < CoursePub > list = new ArrayList < > ( ) ; for ( SearchHit hit : searchHits ) { CoursePub coursePub = new CoursePub ( ) ; / / 取出source Map < String , Object > sourceAsMap = hit.getSourceAsMap ( ) ; / / 取出名称 |