import com.adc.da.budget.entity.Project;
import com.adc.da.budget.repository.ProjectRepository;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List;
@Service
public class TestService {
@Autowired
ProjectRepository projectRepository;
@PostConstruct
public void testGetCount()
{
String name="一体化";
List<Project> projectList=projectRepository.findByNameLike("*"+name+"*");
if(projectList!=null){
for(Project project: projectList){
System.out.println(project);
}
}
System.out.println("***************一体化********");
QueryBuilder query= QueryBuilders.boolQuery().must(QueryBuilders.wildcardQuery("name","*"+name+"*"));
Iterable<Project> projects=projectRepository.search(query);
for(Project project: projects){
System.out.println(project);
}
System.out.println("^^^^^^^^^^^^^^^^^^^^^$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
}
ES: 模糊查询
最新推荐文章于 2024-04-08 03:01:34 发布