Spring Data Elasticsearch - 基本案例

This commit is contained in:
liqiangqiang
2017-06-14 19:33:21 +08:00
parent eaa680004c
commit a6c910d3d9
2 changed files with 70 additions and 5 deletions

View File

@@ -15,23 +15,52 @@ import java.util.List;
*/
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);
// @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);
/**
* LIKE 语句查询
*
* @param description
* @param page
* @return
*/
Page<City> findByDescriptionLike(String description, Pageable page);
Page<City> findByScoreBetween(Integer score, Pageable page);
}

View File

@@ -5,6 +5,10 @@ import org.spring.springboot.domain.City;
import java.util.List;
/**
* 城市 ES 业务接口类
*
*/
public interface CityService {
/**
@@ -15,13 +19,45 @@ public interface CityService {
*/
Long saveCity(City city);
/**
* 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);
/**
* 查询城市描述
*
* @param description
* @return
*/
List<City> findByDescription(String description);
/**
* NOT 语句查询
*
* @param description
* @return
*/
List<City> findByDescriptionNot(String description);
/**
* LIKE 语句查询
*
* @param description
* @return
*/
List<City> findByDescriptionLike(String description);
}