ElasticSearch+IK分词器搭建

ElasticSearch+IK分词器搭建

startup elastic

adduser elastic
su elastic
cd ~/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz
tar -zxvf ./elasticsearch-6.4.1.tar.gz
mv ./elasticsearch-6.4.1 elastic
cd ./elastic
sudo ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.1/elasticsearch-analysis-ik-6.4.1.zip
./bin/elasticsearch

error

  • max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
    文件描述符过小
    sudo vim /etc/security/limits.conf
    elastic soft nofile 65536
    elastic hard nofile 65536
  • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    虚拟内存过小
    sudo sysctl -w vm.max_map_count=262144

添加守护进程

sudo vim /lib/systemd/system/elastic.service

[Unit]
Description=ElasticSearch Service
After=network.target

[Service]
Type=forking
User=elastic
ExecStart=/home/elastic/elastic/bin/elasticsearch
ExecReload=
ExecStop=

[Install]
WantedBy=multi-user.target

systemctl enable ./elastic.service

create index

curl -XPUT  http://localhost:9200/alert

create mapping

curl -XPOST http://localhost:9200/alert/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
    "properties":{
         "column":{
             "type":"keyword"
         },
         "title":{
             "type":"text",
             "analyzer":"ik_smart",
             "search_analyzer":"ik_smart"
         },
         "content":{
             "type":"text",
             "analyzer":"ik_smart",
             "search_analyzer":"ik_smart"
         },
         "pushTime":{
             "type":"long"
         }
    }
}'

test data

curl -XPOST http://localhost:9200/alert/fulltext/1 -H 'Content-Type:application/json' -d'
{
    "column":"优讯",
    "title":"TDH公司推出实物交割的BTC掉期合约",
    "content":"在线利率互换市场trueEx旗下trueDigital Holdings将推出首个有保证金、实物交割的比特币掉期合约,使机构投资者能够以类似于目前交易和对冲利率、外汇和大宗商品的方式,管理比特币的风险敞口。(美通社)",
    "pushTime":1538594693000
}'

curl -XPOST http://localhost:9200/alert/fulltext/2 -H 'Content-Type:application/json' -d'
{
    "column":"优讯",
    "title":"美国众议员提议建立“基于共识的区块链定义”",
    "content":"美国众议员Doris Matsui和Brett Guthrie于周一提出了《2018年区块链促进法》,提议建立一个“基于共识的区块链定义”。如果法案通过,将成立一个工作组为政府研究区块链并创建其定义。该小组还将研究行政部门如何使用区块链。(Coindesk)",
    "pushTime":1538594693000
}'

curl -XPOST http://localhost:9200/alert/fulltext/3 -H 'Content-Type:application/json' -d'
{
    "column":"优讯",
    "title":"日本金融厅研讨会实况:对加密行业的监管规范提出了几点意见",
    "content":"在日本金融厅第六次加密货币交易所研讨会上,关于加密行业的监管规范提出了以下几点意见:1、处理有问题的虚拟货币;2、加强对客户财产的管理和维护;3、减少与投机交易相关的风险;4、确保交易的透明度并防止利益冲突。(Bitpress)",
    "pushTime":1538594693000
}'

curl -XPOST http://localhost:9200/alert/fulltext/4 -H 'Content-Type:application/json' -d'
{
    "column":"优讯",
    "title":"日本金融厅研讨会实况:Zaif交易所推迟对客户的损失赔偿",
    "content":"在日本金融厅第六次加密货币交易所研讨会上,距离Zaif交易所被盗已有三周,仍未披露具体情况,对客户的损失赔偿也被推迟。Zaif表示,仍在考虑具体细节。(日经新闻)",
    "pushTime":1538594693000
}'

test search

curl -XPOST http://localhost:9200/alert/fulltext/_search -H 'Content-Type:application/json' -d'
{
    "query": { "multi_match" : {"query" : "日本" , "fields": [ "title" , "content" ]}},
    "highlight" : {
        "pre_tags" : ["<highlight>"],
        "post_tags": ["</highlight>"],
        "fields": {
            "title" : {},
            "content" : {}
        }
    }
}'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值