Magento搜索接入ElasticSearch
基于M2.3.5-p1和ElasticSearch 7.8
ElasticSearch
安装
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
yum install --enablerepo=elasticsearch elasticsearch
如果网络有问题的话,也可以使用迅雷等工具下载,再上传到服务器安装。
链接:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-x86_64.rpm
yum localinstall elasticsearch-7.8.1-x86_64.rpm
配置
ElasticSearch具有三个配置文件:
elasticsearch.yml
用于配置Elasticsearchjvm.options
用于配置Elasticsearch JVM设置log4j2.properties
用于配置Elasticsearch日志记录
vim /etc/elasticsearch/elasticsearch.yml
cluster.name: my-application
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 127.0.0.1
http.port: 9200
修改用户和分组
因为不允许root用户执行,新建用户es和分组es,用来执行
修改以下目录的所有者 chown -R es.es xxxx
/usr/share/elasticsearch
/var/lib/elasticsearch
/var/log/elasticsearch
/etc/sysconfig/elasticsearch
/etc/elasticsearch
启动
/usr/share/elasticsearch/bin/elasticsearch
测试
curl -i 127.0.0.1:9200
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 532
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "GHNZzGvlRsOyqgpcsgkGrw",
"version" : {
"number" : "7.8.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89",
"build_date" : "2020-07-21T16:40:44.668009Z",
"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"
}
M2后台配置
Stores
- Configuration
- Catalog
- Catalog
- Catalog Search
更新缓存和刷新索引
bin/magento cache:clean
bin/magento indexer:reindex
到这里,就完成了商品搜索从MySQL到Elasticsearch的切换,Elasticsearch的安装配置到这里也就结束了。
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/25/magento-search-access-elasticsearch/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论