欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

elasticsearch-7.8.0 + ik中文分词,打造全文搜索

程序员文章站 2024-03-25 18:17:28
...

我的环境是centos7 64位的系统,需要jdk1.8以上版本

elasticsearch官网下载地址:

wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz &

下载ik分词插件:https://github.com/medcl/elasticsearch-analysis-ik/releases

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.8.0/elasticsearch-analysis-ik-7.8.0.zip

下载完elasticsearch直接解压就行了,我是解压到/usr/local/elasticsearch-7.8.0文件夹

mkdir /usr/local/elasticsearch-7.8.0/plugins/ik  

把ik分词插件解压到usr/local/elasticsearch-7.8.0/plugins/ik 文件夹

 

新建用户组 groupadd esgroup

新增用户 useradd esroot -g esgroup -p esroot

设置权限 chown -R esroot:esgroup /usr/local/elasticsearch-7.8.0

切换权限 su esroot

用root是无法启动的哈!要用esroot用户启动:/usr/local/elasticsearch-7.8.0/bin/elasticsearch&

curl 127.0.0.1:9200 查看elasticsearch是否启动成功

[aaa@qq.com plugins]$ curl 127.0.0.1:9200
{
  "name" : "email.buruyouni.com",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2kk4PsMnQHevnK8w1kkUAQ",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

查看ik的分词,我这里用的是:ik_max_word模式

curl -H "Content-Type: application/json" http://localhost:9200/_analyze  -X POST  --data '{ "text":"广东省佛山市","analyzer": "ik_max_word"}'

{
    "tokens": [
        {
            "token": "广东省",
            "start_offset": 0,
            "end_offset": 3,
            "type": "CN_WORD",
            "position": 0
        },
        {
            "token": "广东",
            "start_offset": 0,
            "end_offset": 2,
            "type": "CN_WORD",
            "position": 1
        },
        {
            "token": "省",
            "start_offset": 2,
            "end_offset": 3,
            "type": "CN_CHAR",
            "position": 2
        },
        {
            "token": "佛山市",
            "start_offset": 3,
            "end_offset": 6,
            "type": "CN_WORD",
            "position": 3
        },
        {
            "token": "佛山",
            "start_offset": 3,
            "end_offset": 5,
            "type": "CN_WORD",
            "position": 4
        },
        {
            "token": "市",
            "start_offset": 5,
            "end_offset": 6,
            "type": "CN_CHAR",
            "position": 5
        }
    ]
}

添加,put请求类型,添加id=3的文档(我这里用的是postman啦)

elasticsearch-7.8.0 + ik中文分词,打造全文搜索

post请求类型,更新id=5的文档的id字段和total_price字段:

elasticsearch-7.8.0 + ik中文分词,打造全文搜索

 

delete请求类型,删除id=3的文档:

elasticsearch-7.8.0 + ik中文分词,打造全文搜索

 

 

相关标签: 服务器监控