How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

  • How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)已关闭评论
  • 74 views

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/

以下为带译文的内容。需要看原始内容可访问以上链接。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 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”。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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' );

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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 文件,则可能需要导航到 应用程序管理 → 应用程序设置.

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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 仪表板,然后单击同步。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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 连接到您的服务器。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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 访问应用程序。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

Now, head back to the SSH Terminal window and use the above credentials to get into the application.
现在,返回 SSH 终端窗口并使用上述凭据进入应用程序。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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.
启动终端并使用您的主凭证登录。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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' 以获取应用程序列表。

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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]

How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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:
    您将看到如下输出:
  • How to Configure Elasticsearch on WordPress on Cloudways (如何在 Cloudways 上的 WordPress 上配置 Elasticsearch)

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。

米粒在线
  • 本文由 发表于 2024年11月8日22:39:23
  • 转载请务必保留本文链接:https://www.miliol.org/129188.html
网站建设

从并发20到并发120之laravel性能优化

调优成果 遇到问题 单台服务并发20,平均响应时间1124ms,通过htop观察,发现cpu占用率达到100%(包括sleep的进程),内存几乎没怎么用。 调优后 单机最大吞吐量达到1...
wordpress主题

为了WordPress运行效率翻倍我用Cyberpanel替代了宝塔面板

因为我的博客最近这段时间总是莫名其妙的卡成狗,用的是应该是某个插件的原因,正好许久没折腾了就追求刺激,准备重新使用我以前心心恋恋的 openlitespeed,当初测试在都安装插件的情况下 NGINX...