es安装分词器
es安装分词器
一.安装es
1.解压
tar xvf elasticsearch-8.12.2-linux-aarch64.tar.gz -C /usr/local/
2.创建一个用户并授权
groupadd esgroup
useradd esuser -p 123456
chown -R esuser:esgroup /usr/local/elasticsearch-8.12.2
3.修改配置
#修改sysctl.conf
vim /etc/sysctl.conf
#在文件的最后一行添加
vm.max_map_count=262144
调整 elasticsearch.yml
#进入config文件夹
cd /usr/local/elasticsearch-8.12.2/config
#修改elasticsearch.yml 配置信息
vim elasticsearch.yml
在文件夹的最后一行添加:
ingest.geoip.downloader.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"
4.切换用户再次启动
su esuser
#进入elasticsearch bin目录下面
cd /usr/local/elasticsearch-8.12.2/bin
#启动
./elasticsearch
5.访问
访问之后如果拒绝
分析应该是:elasticsearch开启了认证和http加密
继续操作elasticsearch 系统会关闭服务
为了测试,先关闭一下认证,继续修改elasticsearch.yml
#切换到root用户
su root
#进入config文件夹
cd /usr/local/elasticsearch-8.12.2/config
#修改elasticsearch.yml 配置信息
vim elasticsearch.yml
关闭xpack认证
xpack.security.enabled: true 改成 false
与客户端http链接是否加密,先选择不加密
xpack.security.http.ssl: true 改成 false
6.却换用户,再次启动
#却换用户
su esuser
#进入elasticsearch bin目录下面
cd /usr/local/elasticsearch-8.12.2/bin
#启动
./elasticsearch
二.安装分词器
下载成功后解压放到es的plugins目录下,并改名字为ik
unzip elasticsearch-analysis-ik-8.12.2.zip -d /usr/local/elasticsearch-8.12.2/plugins/ik
chmod -R 777 /usr/local/elasticsearch-8.12.2/plugins/ik
启动es,看到ik分词器已经加载进来
三.安装kibana并测试
1解压
tar xvf kibana-8.12.2-linux-aarch64.tar.gz -C /usr/local/
2.启动
cd /usr/local/kibana-8.12.2/config/
vim kibana.yml
server.port: 5601 #kibana端口
server.host: "0.0.0.0" #所有主机都能访问,或者也可以指定一个ip
server.publicBaseUrl: "http://192.168.199.233:5601"
elasticsearch.hosts: ["http://192.168.199.233:9200"] #配置es的访问地址 高版本是.hosts 低版本的是url
i18n.locale: "zh-CN"
cd /usr/local/kibana-8.12.2/bin
./kibana --allow-root
四.测试
#测试分词
POST /_analyze
{
"text":"合理小姐是凑巧先生独一无二的女主角",
"analyzer": "ik_max_word"
}
五.es8是否支持向量查询
在es8中是支持向量查询的
PUT image-index
{
"mappings": {
"properties": {
"image-vector": {
"type": "dense_vector",
"dims": 3
},
"title":{
"type": "text"
},
"file-type": {
"type": "keyword"
},
"my_label": {
"type" : "text"
}
}
}
}
POST image-index/_bulk
{ "index": {} }
{ "image-vector": [-5, 9, -12], "title": "Image A", "file-type": "jpeg", "my_label": "red" }
{ "index": {} }
{ "image-vector": [10, -2, 3], "title": "Image B", "file-type": "png", "my_label": "blue" }
{ "index": {} }
{ "image-vector": [4, 0, -1], "title": "Image C", "file-type": "gif", "my_label": "red" }
POST image-index/_search
{
"knn": {
"field": "image-vector",
"query_vector": [-5, 10, -12],
"k": 10,
"num_candidates": 100
},
"fields": [ "title", "file-type" ]
}
查询的结果
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 6,
"relation": "eq"
},
"max_score": 0.99937135,
"hits": [
{
"_index": "image-index",
"_id": "WahncJMBn1Jiu5-p-dJ2",
"_score": 0.99937135,
"_source": {
"image-vector": [
-5,
9,
-12
],
"title": "Image A",
"file-type": "jpeg",
"my_label": "red"
},
"fields": {
"file-type": [
"jpeg"
],
"title": [
"Image A"
]
}
},
{
"_index": "image-index",
"_id": "XKhtcJMBn1Jiu5-ptNI9",
"_score": 0.99937135,
"_source": {
"image-vector": [
-5,
9,
-12
],
"title": "Image A",
"file-type": "jpeg",
"my_label": "red"
},
"fields": {
"file-type": [
"jpeg"
],
"title": [
"Image A"
]
}
},
{
"_index": "image-index",
"_id": "W6hncJMBn1Jiu5-p-dJ2",
"_score": 0.44084936,
"_source": {
"image-vector": [
4,
0,
-1
],
"title": "Image C",
"file-type": "gif",
"my_label": "red"
},
"fields": {
"file-type": [
"gif"
],
"title": [
"Image C"
]
}
},
{
"_index": "image-index",
"_id": "XqhtcJMBn1Jiu5-ptNI9",
"_score": 0.44084936,
"_source": {
"image-vector": [
4,
0,
-1
],
"title": "Image C",
"file-type": "gif",
"my_label": "red"
},
"fields": {
"file-type": [
"gif"
],
"title": [
"Image C"
]
}
},
{
"_index": "image-index",
"_id": "WqhncJMBn1Jiu5-p-dJ2",
"_score": 0.19600916,
"_source": {
"image-vector": [
10,
-2,
3
],
"title": "Image B",
"file-type": "png",
"my_label": "blue"
},
"fields": {
"file-type": [
"png"
],
"title": [
"Image B"
]
}
},
{
"_index": "image-index",
"_id": "XahtcJMBn1Jiu5-ptNI9",
"_score": 0.19600916,
"_source": {
"image-vector": [
10,
-2,
3
],
"title": "Image B",
"file-type": "png",
"my_label": "blue"
},
"fields": {
"file-type": [
"png"
],
"title": [
"Image B"
]
}
}
]
}
}
浙公网安备 33010602011771号