我需要除了查询之外,我还会查看我的实体“Terreno0101”的“entorno”字段。 我知道环境的价值。
@RequestMapping(value = "/_search/terreno-0101-s",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Transactional(readOnly = true)
public ResponseEntity<List<Terreno0101DTO>> searchTerreno0101S(@RequestParam Map<String,String> requestParams, Pageable pageable)
throws URISyntaxException {
String query = requestParams.get("query");
String entorno = requestParams.get("entorno");
log.debug("REST request to search for a page of Terreno0101S for query {}", query);
Page<Terreno0101> page = terreno0101Service.search(requestParams.get("query"), pageable);
HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/terreno-0101-s");
return new ResponseEntity<>(terreno0101Mapper.terreno0101SToTerreno0101DTOs(page.getContent()), headers, HttpStatus.OK);
}
服务
@Transactional(readOnly = true)
public Page<Terreno0101> search(String query, Pageable pageable) {
log.debug("Request to search for a page of Terreno0101S for query {}", query);
return terreno0101SearchRepository.search(queryStringQuery(query), pageable);
}
存储库
public interface Terreno0101SearchRepository extends ElasticsearchRepository<Terreno0101, Long> {
}
但不是添加到我的服务和/或存储库中,因为只查找那些满足查询条件的内容,而且“entorno”是获取我的字段。
答案 0 :(得分:2)
您可以使用QueryBuilders API为此构建查询:
return terreno0101SearchRepository.search(QueryBuilders.boolQuery()
.must(queryStringQuery(query)).must(matchQuery("entorno", entorno)));
您还可以使用@Query annotation.
构建相同类型的查询您甚至可以将过滤作为queryStringQuery的一部分包含在内:
"entorno:value searchString"