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:
@@ -15,23 +15,52 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface CityRepository extends ElasticsearchRepository<City, Long> {
|
public interface CityRepository extends ElasticsearchRepository<City, Long> {
|
||||||
/**
|
/**
|
||||||
|
* AND 语句查询
|
||||||
|
*
|
||||||
* @param description
|
* @param description
|
||||||
* @param score
|
* @param score
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<City> findByDescriptionAndScore(String description, Integer score);
|
List<City> findByDescriptionAndScore(String description, Integer score);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OR 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @param score
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescriptionOrScore(String description, Integer score);
|
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);
|
Page<City> findByDescription(String description, Pageable page);
|
||||||
|
|
||||||
// @Query("{\"bool\" : {\"must\" : {\"term\" : {\"description\" : \"?0\"}}}}")
|
/**
|
||||||
// Page<City> findByDescription(String description, Pageable pageable);
|
* NOT 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @param page
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
Page<City> findByDescriptionNot(String description, Pageable page);
|
Page<City> findByDescriptionNot(String description, Pageable page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @param page
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
Page<City> findByDescriptionLike(String description, Pageable page);
|
Page<City> findByDescriptionLike(String description, Pageable page);
|
||||||
|
|
||||||
Page<City> findByScoreBetween(Integer score, Pageable page);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import org.spring.springboot.domain.City;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 城市 ES 业务接口类
|
||||||
|
*
|
||||||
|
*/
|
||||||
public interface CityService {
|
public interface CityService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,13 +19,45 @@ public interface CityService {
|
|||||||
*/
|
*/
|
||||||
Long saveCity(City city);
|
Long saveCity(City city);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AND 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @param score
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescriptionAndScore(String description, Integer score);
|
List<City> findByDescriptionAndScore(String description, Integer score);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OR 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @param score
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescriptionOrScore(String description, Integer score);
|
List<City> findByDescriptionOrScore(String description, Integer score);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询城市描述
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescription(String description);
|
List<City> findByDescription(String description);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescriptionNot(String description);
|
List<City> findByDescriptionNot(String description);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE 语句查询
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<City> findByDescriptionLike(String description);
|
List<City> findByDescriptionLike(String description);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user