Elasticsearch IK分词器安装

Elasticsearch IK分词器安装
一.更新
sudo yum update -y


sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm


sudo yum install npm

sudo yum install -y git

sudo yum install -y bzip2
二.下载Elasticsearch-head
git clone git://github.com/mobz/elasticsearch-head.git
三.配置Elasticsearch-head
#es启动时需要使用非root用户,所有创建一个ess用户:
useradd ess
#为hadoop用户添加密码:
echo 123456 | passwd --stdin ess
#将bigdata添加到sudoers
echo "ess ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/ess

#改变Elasticsearch-head所属用户
sudo chown -R ess:ess ./elasticsearch-head
#进入到elasticsearch-head中
cd elasticsearch-head
#编译安装
npm install
打开elasticsearch-head-master/Gruntfile.js,找到下面connect属性,新增hostname: '0.0.0.0',
注:如若hostname: '0.0.0.0'不成功,则改成本台虚拟机的ip
		connect: {
                        server: {
                                options: {
                                        hostname: '0.0.0.0',
                                        port: 9100,
                                        base: '.',
                                        keepalive: true
                                }
                        }
                }
#启动Elasticsearch-head
npm run install
四.下载并开启Elasticsearch的远程连接
注:本台虚拟机必须安装jdk环境(jdk要求1.8.20以上)
#上传es安装包并解压es
tar -zxvf elasticsearch-5.4.3.tar.gz -C /bigdata/

#修改配置
vi /bigdata/elasticsearch-5.4.3/config/elasticsearch.yml
#es绑定的ip地址
network.host: 192.168.10.16
#开启远程连接
编辑elasticsearch-5.4.3/config/elasticsearch.yml,加入以下内容:
http.cors.enabled: true
http.cors.allow-origin: "*"

#给elasticsearch相应的目录添加权限
chown -R ess:ess ./elasticsearch-5.4.3

#进入ess用户启动elasticsearch
elasticsearch-5.4.3/bin/elasticsearch -d

#出现错误
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
#修改错误
#用户最大可创建文件数太小
sudo vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536

#查看可打开文件数量
ulimit -Hn


#最大虚拟内存太小
sudo vi /etc/sysctl.conf 
vm.max_map_count=262144

#查看虚拟内存的大小
sudo sysctl -p

#重启linux
	shutdown -r now
#通过浏览器访问ES
	192.168.253.205:9200
五.安装IK分词器
#下载对应版本的插件
https://github.com/medcl/elasticsearch-analysis-ik/releases

#首先下载es对应版本的ik分词器的zip包,上传到es服务器上,在es的安装目录下有一个plugins的目录,在这个目录下创建一个叫ik的目录然后将解压好的内容,拷贝到ik目录并重启

#练习测试
#创建索引名字叫news
curl -XPUT http://192.168.100.211:9200/news

#创建mapping(相当于数据中的schema信息,表名和字段名以及字段的类型)
curl -XPOST http://192.168.100.211:9200/news/fulltext/_mapping -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
    
}'


curl -XPOST http://192.168.100.211:9200/news/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}'

curl -XPOST http://192.168.100.211:9200/news/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}'

curl -XPOST http://192.168.100.211:9200/news/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'

curl -XPOST http://192.168.100.211:9200/news/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'

curl -XPOST http://192.168.100.211:9200/news/fulltext/_search  -d'
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<font color='red'>", "<tag2>"],
        "post_tags" : ["</font>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}'

-------------------------------------------------------------------


curl -XGET 'http://192.168.100.211:9200/_analyze?pretty&analyzer=ik_max_word' -d '联想是全球最大的笔记本厂商'

curl -XGET 'https://192.168.100.211:9200/_analyze?pretty&analyzer=ik_smart' -d '联想是全球最大的笔记本厂商'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值