Tony's Blog

Magento 2安装ElasticSearch 6.x搜索引擎及ElasticSearch Module ElasticSuite

ElasticSearch Server 安装步骤

  • 安装jre环境
    • Debian/Ubuntu/Other APT based distros :
  1. sudo apt-get install openjdk-8-jre
  • 安装ElasticSearch
    • Install via APT
  1. wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
  2. sudo apt-get install apt-transport-https
  3. echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
  • 安装ElasticSearch
  1. sudo apt-get update && sudo apt-get install elasticsearch
  • 启动ElastivSearch
    • 先给个权限
  1. sudo chmod 777 /var/log/elasticsearch/*
  2. sudo service elasticsearch start
  • 测试是否启动成功
  1. curl localhost:9200
  • 查看安装目录
  1. curl "localhost:9200/_nodes/settings?pretty=true"
  • 进入安装目录
  1. cd /usr/share/elasticsearch
  • 安装插件
  1. bin/elasticsearch-plugin install analysis-phonetic
  2. bin/elasticsearch-plugin install analysis-icu
  • 重启Elastivserach
  1. sudo service elasticsearch restart

至此,我们已经成功的安装了ElasticSearch搜索引擎


ElasticSearch Module 安装步骤

  • Composer 安装
  1. composer require smile/elasticsuite
  • 启用module并且运行ElasticSuite
  1. bin/magento module:enable Smile_ElasticsuiteCore Smile_ElasticsuiteCatalog Smile_ElasticsuiteSwatches Smile_ElasticsuiteCatalogRule Smile_ElasticsuiteVirtualCategory Smile_ElasticsuiteThesaurus Smile_ElasticsuiteCatalogOptimizer Smile_ElasticsuiteTracker
  • 配置ElasticSuite
  1. bin/magento config:set -l smile_elasticsuite_core_base_settings/es_client/servers localhost:9200
  2. bin/magento config:set -l smile_elasticsuite_core_base_settings/es_client/enable_https_mode 0
  3. bin/magento config:set -l smile_elasticsuite_core_base_settings/es_client/enable_http_auth 0
  4. bin/magento config:set -l smile_elasticsuite_core_base_settings/es_client/http_auth_user ""
  5. bin/magento config:set -l smile_elasticsuite_core_base_settings/es_client/http_auth_pwd ""
  6. bin/magento app:config:import
  • 运行indexer,重建索引
  1. bin/magento index:reindex catalogsearch_fulltext
  2. bin/magento index:reindex elasticsuite_categories_fulltext
  3. bin/magento index:reindex elasticsuite_thesaurus

禁用ElasticSearch Module

  1. bin/magento module:disable Smile_ElasticsuiteCore Smile_ElasticsuiteCatalog Smile_ElasticsuiteSwatches Smile_ElasticsuiteCatalogRule Smile_ElasticsuiteVirtualCategory Smile_ElasticsuiteThesaurus Smile_ElasticsuiteCatalogOptimizer Smile_ElasticsuiteTracker --clear-static-content

删除插件

  • cd 到magento2 根目录下
  • 禁用插件
  • 用composer移除插件
  1. composer remove mirasvit/module-search-elastic-ultimate
  2. composer remove smile/elasticsuite
  3. sudo apt-get --purge autoremove elasticsearch
  4. sudo rm -rf /var/lib/elasticsearch/
  5. sudo rm -rf /etc/elasticsearch

ElasticSuite数据库完整卸载

  1. DELETE FROM setup_module where module='Smile_ElasticsuiteCore';
  2. DELETE FROM setup_module where module='Smile_ElasticsuiteCatalog';
  3. DELETE FROM setup_module where module='Smile_ElasticsuiteCatalogRule';
  4. DELETE FROM setup_module where module='Smile_ElasticsuiteSwatches';
  5. DELETE FROM setup_module where module='Smile_ElasticsuiteCatalogOptimizer';
  6. DELETE FROM setup_module where module='Smile_ElasticsuiteThesaurus';
  7. DELETE FROM setup_module where module='Smile_ElasticsuiteTracker';
  8. DELETE FROM setup_module where module='Smile_ElasticsuiteVirtualCategory';
  9. DELETE FROM eav_attribute where attribute_code='virtual_rule';
  10. DELETE FROM eav_attribute where attribute_code='is_virtual_category';
  11. DELETE FROM eav_attribute where attribute_code='virtual_category_root';
  12. DELETE FROM smile_elasticsuite_optimizer;
  13. DELETE FROM smile_elasticsuite_optimizer_search_container;
  14. DROP TABLE smile_elasticsuite_optimizer_search_container;
  15. DROP TABLE smile_elasticsuite_optimizer;
  16. DROP TABLE smile_elasticsuite_relevance_config_data;
  17. DROP TABLE smile_elasticsuite_thesaurus_expanded_terms;
  18. DROP TABLE smile_elasticsuite_thesaurus_reference_terms;
  19. DROP TABLE smile_elasticsuite_thesaurus_store;
  20. DROP TABLE smile_elasticsuite_thesaurus;
  21. DROP TABLE smile_virtualcategory_catalog_category_product_position;
  22. DROP TABLE smile_elasticsuitecatalog_search_query_product_position;
  23. DROP TABLE smile_elasticsuitecatalog_category_filterable_attribute;
  24. ALTER TABLE catalog_eav_attribute DROP COLUMN is_displayed_in_autocomplete;
  25. ALTER TABLE catalog_eav_attribute DROP COLUMN is_used_in_spellcheck;
  26. ALTER TABLE catalog_eav_attribute DROP COLUMN facet_min_coverage_rate;
  27. ALTER TABLE catalog_eav_attribute DROP COLUMN facet_max_size;
  28. ALTER TABLE catalog_eav_attribute DROP COLUMN facet_sort_order;
  29. ALTER TABLE catalog_eav_attribute DROP COLUMN display_pattern;
  30. ALTER TABLE catalog_eav_attribute DROP COLUMN display_precision;

至此,整个过程就结束了,希望帮到大家。

参考

Install Server Guide
https://github.com/Smile-SA/elasticsuite/wiki/ServerConfig-6.x
Magento 2 Module Install
https://github.com/Smile-SA/elasticsuite/wiki/ModuleInstall
Document:
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
https://mirasvit.com/docs/module-search-elastic-ultimate/current/p