mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-13 21:43:45 +08:00
spring-data-elasticsearch - 实战案例详解
This commit is contained in:
@@ -14,53 +14,5 @@ import java.util.List;
|
|||||||
* Created by bysocket on 20/06/2017.
|
* Created by bysocket on 20/06/2017.
|
||||||
*/
|
*/
|
||||||
public interface CityRepository extends ElasticsearchRepository<City, Long> {
|
public interface CityRepository extends ElasticsearchRepository<City, Long> {
|
||||||
/**
|
|
||||||
* AND 语句查询
|
|
||||||
*
|
|
||||||
* @param description
|
|
||||||
* @param score
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<City> findByDescriptionAndScore(String description, Integer score);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OR 语句查询
|
|
||||||
*
|
|
||||||
* @param description
|
|
||||||
* @param score
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<City> findByDescriptionOrScore(String description, Integer score);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询城市描述
|
|
||||||
*
|
|
||||||
* 等同于下面代码
|
|
||||||
* @Query("{\"bool\" : {\"must\" : {\"term\" : {\"description\" : \"?0\"}}}}")
|
|
||||||
* Page<City> findByDescription(String description, Pageable pageable);
|
|
||||||
*
|
|
||||||
* @param description
|
|
||||||
* @param page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Page<City> findByDescription(String description, Pageable page);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NOT 语句查询
|
|
||||||
*
|
|
||||||
* @param description
|
|
||||||
* @param page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Page<City> findByDescriptionNot(String description, Pageable page);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LIKE 语句查询
|
|
||||||
*
|
|
||||||
* @param description
|
|
||||||
* @param page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Page<City> findByDescriptionLike(String description, Pageable page);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class CityESServiceImpl implements CityService {
|
|||||||
Float MIN_SCORE = 10.0F; // 由于无相关性的分值默认为 1 ,设置权重分最小值为 10
|
Float MIN_SCORE = 10.0F; // 由于无相关性的分值默认为 1 ,设置权重分最小值为 10
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CityRepository cityRepository;// ES 操作类
|
CityRepository cityRepository; // ES 操作类
|
||||||
|
|
||||||
public Long saveCity(City city) {
|
public Long saveCity(City city) {
|
||||||
City cityResult = cityRepository.save(city);
|
City cityResult = cityRepository.save(city);
|
||||||
|
|||||||
Reference in New Issue
Block a user