設定Elasticsearch服務

Elasticsearch是開放原始碼產品,可讓您從任何來源取得資料、任何格式,並即時搜尋和視覺化資料。

WARNING
雲端基礎結構上的Adobe Commerce不支援Elasticsearch7.11和更新版本。 Adobe Commerce版本2.3.7-p3、2.4.3-p2以及2.4.4和更新版本支援OpenSearch服務。 內部部署安裝仍支援Elasticsearch。

若為Adobe Commerce 2.4.4版或更新版本,請參閱設定OpenSearch服務

  • Elasticsearch會對產品目錄中的產品執行快速和進階搜尋
  • Elasticsearch分析器支援多種語言
  • 支援停用字和同義字
  • 在重新索引操作完成之前,索引不會影響客戶
TIP
Adobe建議您一律為雲端基礎結構專案上的Adobe Commerce設定Elasticsearch,即使您打算為Adobe Commerce應用程式設定協力廠商搜尋工具亦然。 設定Elasticsearch會在第三方搜尋工具失敗時提供後援選項。

使用下列指示在Pro整合環境與入門環境(包括master分支)上進行服務設定。

NOTE
提交Adobe Commerce支援票證以變更Pro生產和中繼環境上的服務組態。

若要啟用Elasticsearch

  1. 對於入門專案,將elasticsearch服務新增到Elasticsearch版本且已配置磁碟空間為MB的.magento/services.yaml檔案。

    code language-yaml
    elasticsearch:
        type: elasticsearch:<version>
        disk: 1024
    

    對於Pro專案,您必須提交Adobe Commerce支援票證以在預備和生產環境中變更Elasticsearch版本。

  2. 設定.magento.app.yaml檔案中的relationships屬性。

    code language-yaml
    relationships:
        elasticsearch: "elasticsearch:elasticsearch"
    
  3. 新增、提交和推送程式碼變更。

    code language-bash
    git add .magento/services.yaml .magento.app.yaml && git commit -m "Enable Elasticsearch" && git push origin <branch-name>
    

    如需這些變更如何影響您環境的詳細資訊,請參閱服務

  4. 部署程式完成後,請使用SSH登入遠端環境。

    code language-bash
    magento-cloud ssh
    
  5. 重新索引目錄搜尋索引。

    code language-bash
    bin/magento indexer:reindex catalogsearch_fulltext
    
  6. 清除快取。

    code language-bash
    bin/magento cache:clean
    
TIP
初始服務安裝之後,您可以更新services.yaml.magento.app.yaml組態檔,以變更已安裝服務的軟體版本。 請參閱變更服務版本以取得升級或降級服務的指引。

Elasticsearch軟體相容性

在雲端基礎結構專案上安裝或升級Adobe Commerce時,請務必檢查Adobe Commerce的Elasticsearch服務版本與ElasticsearchPHP使用者端之間的相容性。

  • 首次安裝 — 確認services.yaml檔案中指定的Elasticsearch版本與為Adobe Commerce設定的ElasticsearchPHP使用者端相容。

  • 專案升級 — 確認新應用程式版本中的ElasticsearchPHP使用者端與安裝在雲端基礎結構上的Elasticsearch服務版本相容。

雲端基礎結構上Adobe Commerce的服務版本和相容性支援取決於雲端基礎結構上部署的版本,有時與Adobe Commerce內部部署支援的版本不同。 請參閱服務版本

若要檢查Elasticsearch軟體相容性

  1. 在本機工作站上,變更至專案目錄。

  2. 顯示使用中環境的Elasticsearch詳細資訊。

    code language-bash
    magento-cloud relationships --property=elasticsearch
    
  3. 或者,您可以使用SSH登入遠端環境。

    code language-bash
    magento-cloud ssh
    
  4. 檢查elasticsearch/elasticsearch的Composer封裝版本。

    code language-bash
    composer show elasticsearch/elasticsearch
    

    在回應中,檢查versions屬性中已安裝的版本。

    code language-terminal
    name     : elasticsearch/elasticsearch
    descrip. : PHP Client for Elasticsearch
    keywords : client, elasticsearch, search
    versions : * v7.17.1
    type     : library
    license  : Apache License 2.0 (Apache-2.0) (OSI approved) https://spdx.org/licenses/Apache-2.0.html#licenseText
    license  : GNU Lesser General Public License v2.1 only (LGPL-2.1-only) (OSI approved) https://spdx.org/licenses/LGPL-2.1-only.html#licenseText
    homepage :
    source   : [git] git@github.com:elastic/elasticsearch-php.git f1b8918f411b837ce5f6325e829a73518fd50367
    dist     : [zip] https://api.github.com/repos/elastic/elasticsearch-php/zipball/f1b8918f411b837ce5f6325e829a73518fd50367 f1b8918f411b837ce5f6325e829a73518fd50367
    path     : ~/vendor/elasticsearch/elasticsearch
    names    : elasticsearch/elasticsearch
    

    您也可以在環境根目錄的composer.lock檔案中找到ElasticsearchPHP使用者端版本。

  5. 從命令列擷取Elasticsearch服務連線詳細資料。

    code language-bash
    vendor/bin/ece-tools env:config:show services
    

    在回應中,尋找Elasticsearch服務端點的IP位址:

    code language-terminal
    | elasticsearch:                                                                                                  |
    +------------------------------------------+----------------------------------------------------------------------+
    | username                                 | null                                                                 |
    | scheme                                   | http                                                                 |
    | service                                  | elasticsearch                                                        |
    | fragment                                 | null                                                                 |
    | ip                                       | 169.254.220.11                                                       |
    | hostname                                 | dzggu33f75wi3sd24lgwtoupxm.elasticsearch.service._.magentosite.cloud |
    | public                                   | false                                                                |
    | cluster                                  | fo3qdoxtla4j4-master-7rqtwti                                         |
    | host                                     | elasticsearch.internal                                               |
    | rel                                      | elasticsearch                                                        |
    | query                                    |                                                                      |
    | path                                     | null                                                                 |
    | password                                 | null                                                                 |
    | type                                     | elasticsearch:6.5                                                    |
    | port                                     | 9200                                                                 |
    +------------------------------------------+----------------------------------------------------------------------+
    
  6. 從服務端點擷取已安裝的Elasticsearch服務version:number

    code language-bash
    curl -XGET <elasticsearch-service-endpoint-ip-address>:9200/
    
    code language-terminal
    {
       "name" : "-AqGi9D",
       "cluster_name" : "elasticsearch",
       "cluster_uuid" : "_yze6-ywSEW1MaAF8ZPWyQ",
       "version" : {
         "number" : "6.5.4",
         "build_flavor" : "default",
         "build_type" : "deb",
         "build_hash" : "82a8aa7",
         "build_date" : "2019-01-23T12:07:18.760675Z",
         "build_snapshot" : false,
         "lucene_version" : "7.5.0",
         "minimum_wire_compatibility_version" : "5.6.0",
         "minimum_index_compatibility_version" : "5.0.0"
    },
    "  tagline" : "You Know, for Search"
    }
    
  7. 檢查Elasticsearch服務和PHP使用者端之間的版本相容性。

    如果版本不相容,請對您的環境設定進行下列其中一項更新:

    • 將ElasticsearchPHP使用者端變更為與Elasticsearch服務版本相容的版本。

      code language-bash
      composer require "elasticsearch/elasticsearch:~<version>"
      
    • services.yaml檔案中的Elasticsearch服務版本變更為與ElasticsearchPHP使用者端相容的版本。

TIP
對於Pro專案,您必須提交Adobe Commerce支援票證,才能僅在StagingProduction環境中安裝或更新服務
指示所需的服務變更,包括更新的.magento.app.yamlservices.yaml檔案,並在票證中說明PHP版本。 如需自行變更PHP版本、擴充功能或環境設定,請參閱​_應用程式組態_​中的PHP設定
若要變更​_即時_​生產環境(僅限Pro),您必須至少提供48小時的通知,讓雲端基礎結構團隊有足夠的時間封送資源並進行安全升級。

重新啟動Elasticsearch服務

如果您需要重新啟動Elasticsearch服務,必須聯絡Adobe Commerce支援。

其他搜尋設定

  • 根據預設,雲端環境的搜尋設定會在您每次部署時重新產生。 您可以使用SEARCH_CONFIGURATION部署變數,在部署之間保留自訂搜尋設定。 請參閱部署變數

  • 在您為專案設定Elasticsearch服務後,請使用管理員UI來測試Elasticsearch連線並自訂Adobe Commerce的Elasticsearch設定。

新增Elasticsearch的外掛程式

您可以選擇將configuration:plugins區段新增至.magento/services.yaml檔案中的Elasticsearch服務,以新增外掛程式以進行Elasticsearch。 例如,下列程式碼會啟用ICU分析和注音分析外掛程式。

elasticsearch:
    type: elasticsearch:<service-version>
    disk: 1024
    configuration:
        plugins:
            - analysis-icu
            - analysis-phonetic

如果您使用Elastic Suite協力廠商外掛程式,您必須ece-tools套件更新至2002.0.19或更新版本。
設定Elastic Suite時,請將組態設定新增至ELASTICSUITE_CONFIGURATION部署變數。 此設定可跨部署儲存設定。

移除Elasticsearch的外掛程式

.magento/services.yaml中的elasticsearch:移除外掛程式專案,並不會如您預期解除安裝或停用它們。 您必須重新索引Elasticsearch資料。 此行為旨在防止依賴這些外掛程式的資料可能遺失或損毀。

若要移除Elasticsearch外掛程式

  1. 從您的.magento/services.yaml檔案中移除Elasticsearch外掛程式專案。

  2. 新增、提交和推送您的程式碼變更。

    code language-bash
    git add .magento/services.yaml
    
    code language-bash
    git commit -m "Remove Elasticsearch plugin"
    
    code language-bash
    git push origin <branch-name>
    
  3. .magento/services.yaml變更提交至您的雲端存放庫。

  4. 重新索引目錄搜尋索引。

    code language-bash
    bin/magento indexer:reindex catalogsearch_fulltext
    
  5. 清除快取。

    code language-bash
    bin/magento cache:clean
    
TIP
如需搭配Adobe Commerce使用或疑難排解Elastic Suite外掛程式的詳細資訊,請參閱Elastic Suite檔案

疑難排解

請參閱下列Adobe Commerce支援文章,以取得疑難排解Elasticsearch問題的說明:

recommendation-more-help
05f2f56e-ac5d-4931-8cdb-764e60e16f26