ElasticSearch5.4.1 搜索引擎搭建文档

Posted Mr黄瑞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch5.4.1 搜索引擎搭建文档相关的知识,希望对你有一定的参考价值。

  1. 安装配置JDK环境
    JDK安装(不能安装JRE)
    JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
    下载包:jdk-8u131-linux-x64.rpm
    yum localinstall jdk-8u131-linux-x64.rpm
  2. mvn 安装
    MVN下载地址
    wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
    tar xzf apache-maven-3.3.9-bin.tar.gz
    mv apache-maven-3.3.9 maven
    vi /etc/profile.d/maven.sh
    export M2_HOME=/home/maven
    export PATH=${M2_HOME}/bin:${PATH}
    source /etc/profile.d/maven.sh
    mvn -version
  3. 安装ElasticSearch5.41
    yum install epel-release
    yum install npm nodejs
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.rpm
    yum localinstall elasticsearch-5.4.1.rpm
    修改配置文件
    vim /etc/elasticsearch/elasticsearch.yml
    修改network.host:localhost 为当前服务器ip地址
    追加2行
    # 增加新的参数,这样head插件可以访问es
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    关闭密码,添加如下一行
    xpack.security.enabled: false
    启动: systemctl start elasticsearch
    开机启动:systemctl enable elasticsearch
    测试
    访问 http://localhost:9200/地址
    默认密码Username: elastic Password: changeme
  4. elasticsearch-head (此操作巨慢)
    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    添加淘宝源(依然慢)
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    npm install
    vim _site/app.js
    查找9200修改参数localhost为本机ip
    npm run start
    测试
    访问 http://localhost:9100/地址,页面显示正常,es连接正常即ok
  5. kibana
    wget https://artifacts.elastic.co/downloads/kibana/kibana-5.4.1-x86_64.rpm
    yum localinstall kibana-5.4.1-x86_64.rpm
    修改配置文件
    vim /etc/kibana/kibana.yml 
    修改elasticsearch.url localhost 为当前服务器ip地址,用户名及密码
    elasticsearch.url: http://localhost:9200
    elasticsearch.username: "elastic"
    elasticsearch.password: "changeme"
    测试:
    curl -u elastic:changeme http://localhost
    http://localhost/status
  6. nginx配置
    安装软件
    yum install nginx httpd-tools
    为 Kibana 创建一个配置文件
    vi /etc/nginx/conf.d/kibana.conf
    加入以下这一段内容:
    server {
        listen 80;
        server_name server_ip;
        location / {
            proxy_pass http://localhost:5601;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection upgrade;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade; 
        }
    }

    注意修改配置文件,server_name ip
    启动Nginx服务
    systemctl start nginx
    systemctl enable nginx
    验证http://localhost

  7. 5.x以上版本的Elasticsearch,Marvel 更换成了X-Pack (此步安装巨慢)
    cd /usr/share/elasticsearch/bin
    ./elasticsearch-plugin install x-pack
    cd /usr/share/kibana/bin
    ./kibana-plugin install x-pack
    systemctl restart elasticsearch
    systemctl restart kibana
  8. elasticsearch-analysis-ik 分词插件 (此步安装巨慢)
    可前往百度云下载:elasticsearch-analysis-ik-5.4.1.zip
    git clone https://github.com/medcl/elasticsearch-analysis-ik
    cd elasticsearch-analysis-ik
    mvn clean
    mvn compile
    mvn package
    拷贝和解压 release 下的文件: #{project_path}/elasticsearch-analysis-ik/target/releases/elasticsearch-analysis-ik-*.zip 到你的 elasticsearch 插件目录, 如: plugins/ik 重启 elasticsearch
    分词插件测试脚本
    技术分享
    创建一个index
    curl -u elastic:changeme -XPUT http://localhost:9200/index
    创建一个mapping
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/_mapping -d‘
    {
        "fulltext": {
                 "_all": {
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "term_vector": "no",
                "store": "false"
            },
            "properties": {
                "content": {
                    "type": "text",
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_max_word",
                    "include_in_all": "true",
                    "boost": 8
                }
            }
        }
    }创建index
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/1 -d‘
    {"content":"世界如此之大"}
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/2 -d‘
    {"content":"世界如此美好"}
    查询
    curl -u elastic:changeme -XPOST http://localhost:9200/index/fulltext/_search  -d‘
    {
        "query" : { "match" : { "content" : "世界" }},
        "highlight" : {
            "pre_tags" : ["<tag1>", "<tag2>"],
            "post_tags" : ["</tag1>", "</tag2>"],
            "fields" : {
                "content" : {}
            }
        }
    }
    
    ik-test













































































以上是关于ElasticSearch5.4.1 搜索引擎搭建文档的主要内容,如果未能解决你的问题,请参考以下文章

elasticsearch5.4.1中怎样创建客户端连接

Spring boot + Spring数据弹性搜索+弹性搜索5.6.0

利用 SeraX 搭建私人搜索引擎

我想搭建自己的收录平台可以吗不知道怎么搭建,也就是自己搭建搜索引擎

从零搭建ES搜索服务基本概念及环境搭建

Apache Solr搜索引擎搭建配置使用详细教程