springboot 整合 elasticsearch

springboot 整合 elasticsearch_第1张图片
spring integrate es.png
背景

最近业务上要做一个频繁查询通话次数的结果,但是通话记录表特别大,有几千万数据,在mysql上面,我们都知道mysql在这样大的数据下性能出现了问题,而且mysql面向的业务一般都是事务型的,为了解决这个问题,我们最终选择了elasticsearch,es是基于apache lucene 去实现的,lucene是一个流行开源的检索服务,性能在开源项目中算是数一数二的了,关于对apache lucene的分析以后会陆续出文章,感兴趣的小伙伴可以交流交流。

本项目是基于spring data 整合 elasticsearch,这个过程中遇到很多坑,在引入es的依赖的时候,会出现问题,最后发现是版本的问题,然后把springboot web 版本升级到最高就得以解决,注意下面项目依赖

ES 对于版本的兼容性要求很高。大版本之间是无法兼容的。具体可以见

springboot 整合 elasticsearch_第2张图片
image.png
  • 项目结构
springboot 整合 elasticsearch_第3张图片
image.png
  • 项目依赖

        
            org.springframework.boot
            spring-boot-starter
            2.0.0.M3
        

        
            org.springframework.boot
            spring-boot-starter-web
            2.0.0.M3
        


 
        
            org.springframework.data
            spring-data-elasticsearch
            3.0.0.RC2
        

        
            org.projectlombok
            lombok
            1.16.12
            provided
        


        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.springframework.boot
            spring-boot-starter-test
            2.0.0.M3
            test
        
    
  • es 配置




    

    
        
    

    


  • repository配置
public interface UserRepository extends ElasticsearchRepository {
    User findByName(String name);
}

完整项目github链接:
https://github.com/myyan/ElasticsearchDemo

你可能感兴趣的:(springboot 整合 elasticsearch)