美文网首页springboot
使用SpringBoot+elasticsearch6.x搭建的

使用SpringBoot+elasticsearch6.x搭建的

作者: 6e3bd4186e4b | 来源:发表于2018-02-10 15:38 被阅读2276次

简述

SpringBoot+elasticsearch6.x搭建的es全文搜索微服务,主要技术:

  • 1、SpringBoot+Mybatis+Elasticsearch6.x框架
  • 2、使用RestHighLevelClient作为搜索java api
  • 3、使用LogStash同步mysql数据

环境安装

  • 创建需用同步数据的表 示例:

     (
       user_id      BIGINT AUTO_INCREMENT
       COMMENT '主键'
         PRIMARY KEY,
       user_name    VARCHAR(30) DEFAULT ''              NOT NULL
       COMMENT '用户名',
       sex          INT DEFAULT '0'                     NOT NULL
       COMMENT '性别',
       login_name   VARCHAR(20) DEFAULT ''              NOT NULL
       COMMENT '登录名',
       login_pwd    VARCHAR(30) DEFAULT ''              NOT NULL
       COMMENT '密码',
       status       INT DEFAULT '0'                     NOT NULL
       COMMENT '状态',
       gmt_create   TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
       gmt_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
     );
    
    
  • elasticsearch安装

    brew install elasticsearch 安装完成之后检查一下elasticsearch状态,使用curl命令 curl localhost:9200

  • 中文分词器安装

    elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.x/elasticsearch-analysis-ik-6.x.zip

    "6.x表示对应的elasticsearch版本"

  • 创建索引和映射

           "mappings":{
               "doc":{
                   "properties":{
                       "@timestamp":{
                           "type":"date"
                       },
                       "@version":{
                           "type":"text",
                           "fields":{
                               "keyword":{
                                   "type":"keyword",
                                   "ignore_above":256
                               }
                           }
                       },
                       "gmt_create":{
                           "type":"date"
                       },
                       "gmt_modified":{
                           "type":"date"
                       },
                       "login_name":{
                           "type":"text",
                           "fields":{
                               "keyword":{
                                   "type":"keyword",
                                   "ignore_above":256
                               }
                           },
                           "analyzer":"ik_max_word"
                       },
                       "login_pwd":{
                           "type":"text",
                           "fields":{
                               "keyword":{
                                   "type":"keyword",
                                   "ignore_above":256
                               }
                           }
                       },
                       "sex":{
                           "type":"long"
                       },
                       "status":{
                           "type":"long"
                       },
                       "user_id":{
                           "type":"long"
                       },
                       "user_name":{
                           "type":"text",
                           "fields":{
                               "keyword":{
                                   "type":"keyword",
                                   "ignore_above":256
                               }
                           },
                           "analyzer":"ik_max_word"
                       }
                   }
               }
           }
       } 
    
    
  • 安装LogStash

    brew install LogStash

使用方法

  • 同步数据脚本
    sh moyu_index_sync.sh

代码地址

https://github.com/LenoXian/elastic-demo

相关文章

网友评论

  • 等风来_5fbd:@Bean
    @Scope("singleton")
    public ESClientDecorator getEsClientDecorator() {
    return new ESClientDecorator(new HttpHost(elasticsProperties.getClusterNodes(), elasticsProperties.getPort()));
    }

    请教下,在注入RestHighLeveCient的时候,使用了 ESClientDecorator,是在这个类里面生成的RestHighLeveCient,这样好处是什么呢?保证RestHighLeveCient是单例?
  • 176fa7649b97:没看懂想表达什么,java代码一点没有贴,想说明什么?浪费时间
    等风来_5fbd:@LeeXian 别生气,好人一生平安,期待博主发布更多好东西,先去git了。
    6e3bd4186e4b:伸手党。。。源码地址不是贴出来了么?git不会用?

本文标题:使用SpringBoot+elasticsearch6.x搭建的

本文链接:https://www.haomeiwen.com/subject/zvactftx.html