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 用于配置Elasticsearch
  • jvm.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后台配置

StoresConfigurationCatalogCatalogCatalog Search

Magento Elasticsearch配置

更新缓存和刷新索引

bin/magento cache:clean
bin/magento indexer:reindex

到这里,就完成了商品搜索从MySQL到Elasticsearch的切换,Elasticsearch的安装配置到这里也就结束了。

上一篇 Magento使用Redis
下一篇 Magento接入MongoDB
目录
文章列表
1 微信小程序开发常用技巧总结
微信小程序开发常用技巧总结
2
使用MyCat实现MySQL读写分离
使用MyCat实现MySQL读写分离
3
Spring Boot RestTemplate 自定义返回码异常处理
Spring Boot RestTemplate 自定义返回码异常处理
4
第三方支付公司及插件文档
第三方支付公司及插件文档
5
Swift - 类初始化和反初始化方法(init与deinit)
Swift - 类初始化和反初始化方法(init与deinit)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。