Sarim Javaid Updated on October 11, 2023 6 Min Read? (轉載自Cloudways作者Sarim Javaid)
薩里姆·賈瓦德 更新 10月 11, 2023 6 分鐘閱讀+
原文地址:https://www.cloudways.com/blog/elasticsearch-on-wordpress/
以下為帶譯文的內容。需要看原始內容可訪問以上鏈接。
hen you run a promotional sale on your online store, you’ll see higher-than-usual traffic as visitors search for their desired products.
當您在網上商店進行促銷活動時,當訪客搜索他們想要的產品時,您會看到比平時更高的流量。
If you’re not prepared, your website could be in danger of lagging or even crashing due to the spike in visitors and search queries. Of course, you can recover your site easily enough if you use good managed WordPress hosting. But it’s not a great situation to be in when you’re looking to satisfy the needs of all those new customers, and retain them as well.
如果您沒有做好準備,您的網站可能會因訪問者和搜索查詢的激增而面臨滯后甚至崩潰的危險。當然,如果您使用良好的托管 WordPress 托管,您可以輕松恢復您的網站。但是,當您希望滿足所有這些新客戶的需求并留住他們時,情況并不理想。
So how do you handle all those requests? One great option is Elasticsearch.
那么,您如何處理所有這些請求呢?一個不錯的選擇是 Elasticsearch。
Table of Contents 目錄
What Is Elasticsearch? 什么是 Elasticsearch?
Why Use Elasticsearch? 為什么使用 Elasticsearch?
How to Configure Elasticsearch on WordPress on Cloudways
如何在 Cloudways 上的 WordPress 上配置 Elasticsearch
Though WordPress’s default search is limited in its functionalities (it doesn’t allow fuzzy search or match with categories and taxonomies), the platform is open-source, meaning a score of developers have made a significant contribution to improving the search functionality. WordPress plugins come to the rescue in order to assist this functionality. Among the broad range of search functionality, plugins like Elasticsearch enhance the result of a search and help improve website performance.
盡管 WordPress 的默認搜索功能有限(它不允許模糊搜索或與類別和分類法匹配),但該平臺是開源的,這意味著許多開發人員為改進搜索功能做出了重大貢獻。WordPress 插件來救援以協助此功能。在廣泛的搜索功能中,Elasticsearch 等插件可以增強搜索結果并有助于提高網站性能。
To get an idea of what Elasticsearch is and how it works, you should read our Co-Founder Aaqib Gadit’s blog post. This post should give you a fair idea of why Cloudways fell in love with this innovative search feature, to the point that it’s integrated within our hosting platform.
要了解 Elasticsearch 是什么以及它是如何工作的,您應該閱讀我們的聯合創始人 Aaqib Gadit 的博客文章。這篇文章應該讓您清楚地了解為什么 Cloudways 愛上了這種創新的搜索功能,以至于它已集成到我們的托管平臺中。
In this tutorial, you’ll learn how to configure Elasticsearch on WordPress. This is simpler than it sounds, especially if you are an active customer of Cloudways. So let’s find out how it is done!
在本教程中,您將學習如何在 WordPress 上配置 Elasticsearch。這比聽起來要簡單,特別是如果您是 Cloudways 的活躍客戶。那么讓我們看看它是如何完成的!
What Is Elasticsearch? 什么是 Elasticsearch?
Elasticsearch was released in 2010 and is used to search queries faster in large databases. Elasticsearch is extremely fast around raw data and is a highly scalable search engine, unlike conventional searches. Elasticsearch has an extensive API that can be integrated into any web application, including WordPress for big data discovery.
Elasticsearch 于 2010 年發布,用于在大型數據庫中更快地搜索查詢。Elasticsearch 處理原始數據的速度非???,并且與傳統搜索不同,它是一個高度可擴展的搜索引擎。Elasticsearch 具有廣泛的 API,可以集成到任何 Web 應用程序中,包括用于大數據發現的 WordPress。
Elasticsearch in WordPress plays an integral part in the poor and slow performance of its default searching capabilities. It may look OK on a site with small databases, but it gets painful for the visitors trying to find their product from 50 different categories. Elasticsearch offers real-time index updates that instantaneously add a new document to the index.
WordPress 中的 Elasticsearch 在其默認搜索功能性能不佳和緩慢方面起著不可或缺的作用。在數據庫較小的網站上看起來可能還不錯,但對于試圖從 50 個不同類別中找到他們的產品的訪問者來說,它會變得很痛苦。Elasticsearch 提供實時索引更新,可立即將新文檔添加到索引中。
Why Use Elasticsearch? 為什么使用 Elasticsearch?
Large websites with directories and archives on various categories can utilize Elasticsearch. Online stores with thousands of products can reduce the search time using Elasticsearch in WordPress. This also improves the user experience as it allows customers to further narrow down their search queries to find the desired product faster.
具有各種類別的目錄和存檔的大型網站可以使用 Elasticsearch。擁有數千種產品的在線商店可以使用 WordPress 中的 Elasticsearch 減少搜索時間。這也改善了用戶體驗,因為它允許客戶進一步縮小搜索查詢范圍以更快地找到所需的產品。
Another amazing feature of Elasticsearch is the ability to monitor applications in real-time. This indexes the search data and makes logs for future analysis. It is a useful feature for e-commerce stores that wish to see trends in customers’ buying behavior and set their marketing strategies accordingly.
Elasticsearch 的另一個驚人功能是能夠實時監控應用程序。這將為搜索數據編制索引并制作日志以供將來分析。對于希望了解客戶購買行為趨勢并相應地設置營銷策略的電子商務商店來說,這是一個有用的功能。
How to Configure Elasticsearch on WordPress on Cloudways (Easy Steps)
如何在 Cloudways 上的 WordPress 上配置 Elasticsearch(簡單步驟)
First of all, to configure Elasticsearch on WordPress, you must keep the following points in mind:
首先,要在 WordPress 上配置 Elasticsearch,您必須牢記以下幾點:
You need to have an account at Cloudways and have backups in place.
您需要在 Cloudways 上擁有一個帳戶并準備好備份。
You should be comfortable with editing WordPress files.
您應該對編輯 WordPress 文件感到滿意。
You should be familiar with WP-CLI.
您應該熟悉 WP-CLI。
Step 1: Enable Elasticsearch
第 1 步:啟用 Elasticsearch
Access the Cloudways platform.
訪問 Cloudways 平臺。
Go to “Settings & Packages” in Server Management.
轉到服務器管理中的“設置和包”。
Click “Packages”. 點擊 “Packages”。
Enable Elasticsearch by selecting the version.
通過選擇版本來啟用 Elasticsearch。
This will enable Elasticsearch on your current server.
這將在您當前的服務器上啟用 Elasticsearch。
Note: Cloudways supports Elasticsearch up to version 7.6. And the ElasticPress plugin also supports the 7.6 version.
注意:Cloudways 支持 Elasticsearch 7.6 及以上版本。并且 ElasticPress 插件也支持 7.6 版本。
Step 2: Install ElasticPress on WordPress
第 2 步:在 WordPress 上安裝 ElasticPress
ElasticPress is an amazing plugin that allows your WordPress website to communicate with Elasticsearch on the server. The plugin is developed by our friends at 10up.com.
ElasticPress 是一個了不起的插件,它允許您的 WordPress 網站與服務器上的 Elasticsearch 通信。該插件由我們在 10up.com 的朋友開發。
According to Taylor Lovett, Project Lead ElasticPress and Director of Web Engineering at 10up:
根據 ElasticPress 項目負責人兼 10up 的 Web 工程總監 Taylor Lovett 的說法:
“MySQL is inherently not created for complex search queries. Elasticsearch, on the other hand, is. To achieve highly relevant search results, filtration, or any other sort of advanced search functionality with WordPress, Elasticsearch is pretty much required. ElasticPress is the easiest and most effective way to integrate Elasticsearch with WordPress.”
“MySQL 本質上不是為復雜的搜索查詢而創建的。另一方面,Elasticsearch 是。要使用 WordPress 實現高度相關的搜索結果、過濾或任何其他類型的高級搜索功能,Elasticsearch 幾乎是必需的。ElasticPress 是將 Elasticsearch 與 WordPress 集成的最簡單、最有效的方法。
According to Chris Wiegman, the Senior Web Engineer at 10up:
根據 10up 的高級 Web 工程師 Chris Wiegman 的說法:
“ElasticPress integrates WordPress’ search with the Elasticsearch, offering an inexpensive way to make users’ search experience more useful. It offers powerful advanced search features with infinitely scalable features, by offloading the search to a service designed specifically to handle this need at large scale.”
“ElasticPress 將 WordPress 的搜索與 Elasticsearch 集成在一起,提供了一種廉價的方式,使用戶的搜索體驗更加有用。它通過將搜索卸載到專為大規模處理此需求而設計的服務,提供強大的高級搜索功能和無限可擴展的功能。
Follow the steps below to install ElasticPress, a WordPress Elasticsearch plugin.
請按照以下步驟安裝 WordPress Elasticsearch 插件 ElasticPress。
Log in to your WordPress dashboard.
登錄到您的 WordPress 儀表板。
Click Add Plugins. 單擊 Add Plugins。
Search for the plugin named “ElasticPress“.
搜索名為 “ElasticPress” 的插件。
Click “Install Now“.
點擊 “Install Now”。
Step 3: Edit the wp-config.php File
第 3 步:編輯 wp-config.php 文件
Next, we need to define the IP, and port Elasticsearch is running from. On Cloudways, Elasticsearch operates from the same server as our WordPress website.
接下來,我們需要定義運行 Elasticsearch 的 IP 和端口。在 Cloudways 上,Elasticsearch 從與我們的 WordPress 網站相同的服務器運行。
Edit your wp-config.php file and define EP_HOST as below.
編輯 wp-config.php 文件并定義EP_HOST如下所示。
/** ElasticPress */ define( 'EP_HOST', 'http://127.0.0.1:9200' );
Note: I added the local IP as ElasticPress runs on the same server as my WordPress and considers it a local environment. Else, you need to mention the server IP address where Elasticsearch is installed.
注意:我添加了本地 IP,因為 ElasticPress 與我的 WordPress 運行在同一臺服務器上,并將其視為本地環境。否則,您需要提及安裝 Elasticsearch 的服務器 IP 地址。
If you cannot upload the updated wp-config.php file, you may need to reset permission by navigating to Application Management → Application Settings.
如果您無法上傳更新的 wp-config.php 文件,則可能需要導航到 應用程序管理 → 應用程序設置.
This will connect your WordPress site to Elasticsearch on your server through the ElasticPress plugin.
這將通過 ElasticPress 插件將您的 WordPress 站點連接到您服務器上的 Elasticsearch。
Get back to WordPress Dashboard → ElasticPress and click on Sync.
返回到 ElasticPress → WordPress 儀表板,然后單擊同步。
Step 4: Build Indexes and Activate Elasticsearch
第 4 步:構建索引并激活 Elasticsearch
Finally, log in to your SSH terminal through Cloudways Platform, build the ES indexes, and activate the feature.
最后,通過 Cloudways 平臺登錄您的 SSH 終端,構建 ES 索引并激活該功能。
Follow the steps below to log in to the SSH terminal:
請按照以下步驟登錄到 SSH 終端:
Head over to the “Server“.
前往“服務器”。
Click “Master Credentials“.
單擊 “Master Credentials”。
Click “Launch SSH Terminal” or use Putty to connect to your server.
單擊“啟動 SSH 終端”或使用 Putty 連接到您的服務器。
From the top left bar, click on Applications and then get into your specific application.
從左上角的欄中,單擊“應用程序”,然后進入您的特定應用程序。
From the right side, create Application Credentials that will be used to access the application via SSH and SFTP.
從右側創建應用程序憑據,用于通過 SSH 和 SFTP 訪問應用程序。
Now, head back to the SSH Terminal window and use the above credentials to get into the application.
現在,返回 SSH 終端窗口并使用上述憑據進入應用程序。
Similarly, you can also access your application directly from the SSH Terminal present inside your server dashboard.
同樣,您也可以直接從服務器儀表板中的 SSH 終端訪問您的應用程序。
Launch the terminal and login with your master credentials.
啟動終端并使用您的主憑證登錄。
Inside your terminal window, run the ‘cd applications’ command to access the applications running on this server.
在終端窗口中,運行“cd applications”命令以訪問此服務器上運行的應用程序。
Type ‘ls’ to get the list of applications.
鍵入 'ls' 以獲取應用程序列表。
You could have just one or twenty applications running on your server. To access the one, you need to work on, type the following command.
您的服務器上可以只運行一個或 20 個應用程序。要訪問您需要處理的那個,請鍵入以下命令。
cd [name of the application] cd [name of the folder]
That’s it! You are in the desired folder of your desired application.
就是這樣!您位于所需應用程序的所需文件夾中。
WP-CLI is required to run ElasticPress specific commands. On Cloudways, each WordPress instance comes pre-installed with WP-CLI.
運行 ElasticPress 特定命令需要 WP-CLI。在 Cloudways 上,每個 WordPress 實例都預裝了 WP-CLI。
First, run the following command to build ES indexes.
首先,執行以下命令構建 ES 索引。
wp elasticpress index --setup
- You will see the output as follows:
您將看到如下輸出:
ES usually activates itself after running the index. But to be on the safer side, run this command to make sure it is enabled.
ES 通常在運行索引后激活自身。但為了更安全,請運行此命令以確保它已啟用。
wp plugin activate elasticpress
Wrapping Up! 結束語!
Deploying Elasticsearch on WordPress or WooCommerce websites will improve the search experience and improve the capability of your site to handle more search queries. Especially for a WooCommerce site as the number of searches increases on an e-commerce website.
在 WordPress 或 WooCommerce 網站上部署 Elasticsearch 將改善搜索體驗,并提高您的網站處理更多搜索查詢的能力。特別是對于 WooCommerce 網站,因為電子商務網站上的搜索量會增加。
Frequently Asked Questions
常見問題解答
What is the best WordPress Elasticsearch plugin?
什么是最好的 WordPress Elasticsearch 插件?
We have already seen ElasticPress in action, which is by far the simplest and most effective plugin. However, other plugins are available with additional functionalities, such as WPSOLR, a paid plugin.
我們已經看到了 ElasticPress 的實際應用,這是迄今為止最簡單、最有效的插件。但是,其他插件具有附加功能,例如付費插件 WPSOLR。
評論