Elasticsearch模糊查询
使用自定义语句进行模糊查询和使用原生的查询语句进行查询
import cn.tedu.mall.pojo.search.entity.SpuForElastic;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
/**
* @Author QingHao
* @Date: 2022/05/17/ 15:36
* @Describe
*/
@Repository
public interface SpuForElasticRepository extends ElasticsearchRepository<SpuForElastic, Long> {
//自定义查询语句
Iterable<SpuForElastic> querySpuForElasticsByNameMatchesOrTitleMatchesOrDescriptionMatchesOrCategoryNameMatches(
String name, String title, String description, String categoryName
);
// 查询spu关键字段中包含"手机"的方法
@Query("{\n" +
" \"bool\": {\n" +
" \"should\": [\n" +
" { \"match\": { \"name\": \"?0\"}},\n" +
" { \"match\": { \"title\": \"?1\"}},\n" +
" { \"match\": { \"description\": \"?2\"}},\n" +
" { \"match\": { \"category_name\": \")3\"}}\n" +
" ]\n" +
" }\n" +
"}")
//当前位置的参数与上面的?0,?1,?2,?3是一1对应的,并不是通过名称进行匹配
Iterable<SpuForElastic> querySearch(String name, String title, String description, String categoryName);
}

浙公网安备 33010602011771号