vlambda博客
学习文章列表

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

User Interfaces

在 Elasticsearch 生态系统中,监控节点和集群以管理和改进它们的性能和状态非常有用。在集群级别可能会出现几个问题,例如:

  • There can be node overheads; for instance, where some nodes can have too many shards allocated and can become a bottleneck for the entire cluster
  • Node shutdown can occur due to many reasons, such as, full disks, hardware failures, and power problems
  • Shard relocation problems or corruptions, in which some shards are unable to be initialized and go online due to some issues.
  • Having very large shards can also be an issue; index performance can decrease due to large Lucene segments merging
  • Empty indices and shards waste memory and resources; however, because every shard has a lot of active threads, if there is a huge number of unused indices and shards, then general cluster performance is degraded
  • There can be other node-related problems such as high CPU usage or full disks

可以通过 API 或一些设计用于 Elasticsearch 的前端来检测故障或性能不佳。

本章介绍的一些前端将允许您在 Elasticsearch 数据中拥有一个有效的 Web 仪表板;这些工作通过监控集群运行状况、备份或恢复数据以及在代码中实现之前允许测试查询来实现。在本章中,我们将仅简要介绍这些前端;这是由于它们的复杂性和大量的特性,这超出了本书的范围。更深入的描述,我建议你看一下 Kibana 的官方文档,该文档位于 https://www.elastic.co/guide/en/kibana/current/index.html

在本章中,我们将探索 Cerebro、ElasticSearchHQ 和 Kibana 的某些方面(涵盖 Kibana 的所有功能超出了本书的范围)。 

Grafana (https://grafana.com/) 是另一种开源解决方案,用于可视化 Elasticsearch 数据和监控公钥基础设施 (PKI),但本书并未涉及。

在本章中,我们将介绍以下食谱:

  • Installing and using Cerebro
  • Installing and using Elasticsearch HQ
  • Installing Kibana
  • Managing Kibana Discovery
  • Visualizing data with Kibana
  • Using Kibana Dev Tools

Installing and using Cerebro

Cerebro 是之前 Elasticsearch 插件 Elasticsearch Kopf (https://github.com/lmenezes/elasticsearch-kopf ) – 由于移除了站点插件,这在 Elasticsearch 5.x 版或更高版本中不起作用。

Cerebro 是查看分片分配和通过图形界面执行常见索引操作的最有用的界面之一。它是完全开源的,它允许您添加用户、密码或 LDAP 身份验证来访问 Web 界面。

Cerebro 是对之前插件的部分重写,它可以作为一个基于 Scala 的 Play Framework 的自工作应用程序服务器。

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch 配方中所述的安装 第 1 章开始

必须安装 Java JVM 版本 8.x 或更高版本才能运行 Cerebro。

如果您使用 Docker Compose(位于 ch01 目录中的 Docker Compose 进行安装,则无需手动安装。 

How to do it...

为了安装 Cerebro,您需要手动下载并安装它。然后,我们将执行以下步骤:

  1. You can download a binary distribution of Cerebro at https://github.com/lmenezes/cerebro/releases. For Linux or macOSX, we can use the following command:
wget -c https://github.com/lmenezes/cerebro/releases/download/v0.8.3/cerebro-0.8.3.tgz
  1. Now, you can extract it, using the following command:
tar xfvz cerebro-0.8.3.tgz
  1. Now, you can execute it using the following command:
cerebro-0.8.3/bin/cerebro
  1. Alternatively, for Windows, use the following command:
cerebro-0.8.3/bin/cerebro.bat
  1. In the console, you should see the following output:
[info] play.api.Play - Application started (Prod)
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:9000
  1. To access the web interface, you will need to navigate to the following address, using your browser,:
http://0.0.0.0:9000/

How it works...

Cerebro 是一个现代的反应式应用程序;它是用 Scala 编写的,使用 Play Framework 进行后端 REST 和 Elasticsearch 通信。此外,它使用了一个 单页应用程序 (SPA) 前端,该前端是用 JavaScript 和 AngularJS 编写的。

默认情况下,Cerebro 绑定到端口 9000。您可以使用浏览器依次导航到http://0.0.0.0:9000 地址以查看以下起始页面:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

在开始页面上,您可以选择预定义的主机,也可以手动插入 Elasticsearch 服务器的地址。如果需要,您可以提供访问 Elasticsearch 集群的凭据。

点击Connect后,如果一切正常,您可以使用nodes视图访问Cerebro主页,如下图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

Cerebro 主页提供了一个非常大的集群和数据概览;从上到下,我们有以下内容:

  • The menu: This is where overview is a link to the home page, rest allows you to send generic REST calls, and by clicking on more, we have additional admin functionalities, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

  • The status line: This is either green, yellow, or red; in this case, it is yellow because my cluster requires more nodes.
  • The line of cluster global statistics: This includes the name of the cluster, the number of nodes, the number of indices, the number of shards, the number of documents, and the size of your data.
  • The filter indices line: This is where you can do the following:
    • Filter the indices by name
    • Show or hide any closed indices
    • Show or hide any special indices (such as index names that start for . (dot) character)
    • Filter by node names
    • Control the indices' pagination
  • The main grid block that contains the node and indices information: In the first column, we have the following:
    • The general cluster control functionalities: Here, the lock symbol allows you to lock the shard relocation at the cluster level (this is useful for cluster restart management). The second symbol allows you to show extra node information, such as the JVM version and Elasticsearch version. The sorting simply allows you to sort the nodes by name.
    • The arrow symbol allows you to execute actions on all the selected indices, such as close, open, refresh, and cache clear.
      • The unassigned shards line: This allows you to check the unassigned shard for the affected indices.
      • The node information: Here, in a single cell we have the node name, node IP, and the heapdiskcpu, or load on the node. If these values are too high, then they appear in red.
  • In the other columns, we have the indices information:
    • This includes the index name, the number of shards, the number of documents, and the total size; from the arrow, you can access an action that can be executed against the index:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

    • The shards are represented as a box with a number; by clicking on it, you can view any additional shard information.

主页或 overview 视图包含非常丰富的有用数据。只需一眼,您就可以确定具有高负载或完整磁盘的节点范围,查看分片在集群中的分布情况,并确定某些索引是否存在问题。

当您单击 index settings 时,会打开一个表单,允许您更改一些索引选项,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

create index 页面允许您轻松创建定义分片、副本或模板的索引,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

集群设置 页面允许您从一个简单的界面更改集群的可变参数。这是高级用法,但是表单的简单性加快了集群的管理,如下图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

可以使用 repositories 菜单来管理存储库;该页面允许您定义要用于未来备份或恢复操作的存储库的名称和类型,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

如果使用接口或 API 创建存储库,则它可用于执行备份和恢复操作。通过单击 shapshot 菜单,您可以访问允许您执行以下操作的页面:

  • On the right-side, you can create a snapshot by selecting the repository, giving it a name, and selecting the indices that need to be backed up
  • On the left-side, there is a list of available snapshots that can be restored, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

There's more...

Cerebro 的初始部分允许您涵盖 Elasticsearch 管理的特殊方面。例如,在 rest 菜单中,您可以访问一个页面,该页面允许您对 Elasticsearch 执行原始 REST 调用,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

Cerebro 不像 Kibana 那样提供数据可视化或发现,但它可以针对 Elasticsearch 端点执行原始 REST 调用。使用此功能,可以针对 Elasticsearch 服务器测试查询。这对于使用 Elasticsearch 的低级客户端非常有用。

rest 接口还允许您将调用导出为 curl 命令。 Cerebro 界面相对较新;新功能目前正在开发中,将在不久的将来发布。

Installing and using Elasticsearch HQ

ElasticSearch HQ (http://www.elastichq.org) 是一个监控和管理应用程序,它同时管理实例和集群。这是一个开源解决方案,可免费用于私人和商业用途。 

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch 第 1 章, 开始

必须安装 Python 版本 3.4, 或更高版本才能运行 ElasticSearch HQ。

如果您使用 Docker Compose(位于 ch01 目录中的 Docker Compose 进行安装,则无需手动安装。 

How to do it...

为了安装 ElasticSearch HQ,您需要手动下载并安装它。然后,我们将执行以下步骤:

  1. You can download a ZIP file or tar.gz distribution of ElasticSearch HQ at https://github.com/ElasticHQ/elasticsearch-HQ/releases. For Linux or macOSX, we can use the following command:
wget -c https://github.com/ElasticHQ/elasticsearch-HQ/archive/v3.5.0.tar.gz
  1. Now you can extract it, using the following command:
tar xfvz v3.5.0.tar.gz
  1. Now you can execute it, using the following commands:
cd v3.5.0
pip install -r requirements.txt
./manage.py runserver
  1. In the console, you should see the following output:
2019-02-16 18:22:26,972 CRIT Supervisor running as root (no user in config file)
2019-02-16 18:22:26,977 INFO supervisord started with pid 1
2019-02-16 18:22:27,980 INFO spawned: 'gunicorn' with pid 8
2019-02-16 18:22:28,983 INFO success: gunicorn entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
loading config /src/elastichq/config/logger.json
2019-02-16 18:22:30,250 INFO engineio server.__init__:140 Server initialized for eventlet.
  1. To access the web interface, you will need to navigate, using your browser, to the following address:
http://0.0.0.0:5000/

How it works...

ElasticSearch HQ 是一个现代反应式应用程序。它由一个使用 Flask 框架 (http://flask.pocoo.org/) 的 Python 编写的后端和一个 SPA 前端组成它是使用 AngularJS 用 Ja​​vaScript 编写的。

默认情况下,ElasticSearch HQ 绑定到端口 5000。您可以使用浏览器导航到http://0.0.0.0:5000 地址,以便 查看以下起始页面:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

在开始页面上,您可以选择预定义的主机,也可以手动插入 Elasticsearch 服务器的地址。在这种情况下,我的实例能够建议我已经使用过的集群。

点击 Connect 后,如果一切正常,您可以访问 ElasticHQ 主页,显示您的 Nodes 视图和 Indices 视图,如下图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

ElasticHQ 主页提供了您的集群和数据的广泛概览;从上到下,我们有以下内容:

  • The menu on the top-right: Here, you can choose from the following options:
    • Indices: This allows you to perform actions on the indices (such as alias, restore, open, or close)
    • Metrics: This offers you metrics about the cluster
    • Nodes: This is a list of nodes that you can use to check node information or the state of a node
    • Diagnostics: This is a page that provides checks on common Elasticsearch parameters
    • REST: This allows you to execute test REST calls
    • Query: This allows you to execute searches on the data
  • Counters: These display the more important items of the cluster, such as Nodes, Indices, Documents, and the Size of the data
  • A line that displays the status of the number of shards
  • The list of Nodes
  • The list of Indices: The color on the left-side refers to the index state (yellows means that some replicas are missing)

如果您访问 Indices |索引摘要菜单,然后您将被带到索引概览页面,如下所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

正如您从前面的屏幕截图中看到的,只需单击一个按钮即可执行许多有用的操作:

  • Refresh: This is to refresh the indices in order to speed up the search of new items, without waiting for the automatic refresh
  • Force Merge: This button reduces the index segments
  • Flush: This writes all the index data onto a disk
  • Clear Cache: This frees the memory
  • Expunge Deleted: This executes a fast force merge that only removes deleted segments
  • Create Index: This adds a new index
  • Re-Index: This moves data between the indices

通过选择索引名称,您可以访问该特定索引及其操作的信息:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

从此视图中,您可以访问更多索引详细信息,如下所示:

  • Metrics (the default page): This provides metrics level information
  • Shards: This provides details about the shards
  • Alias: This allows you to manage the alias for the current index
  • Mappings: This allows you to view the mappings
  • Administration: This allows you to execute administrative commands only on this index

索引管理视图显示在以下屏幕截图中:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

如果您需要了解服务器负载或监控 Elasticsearch KPI,则可以使用 Metrics 按钮访问实时图表:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

要监控节点的配置和参数,您可以从 Nodes 菜单访问详细信息:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

 

ElasticHQ 是唯一的用户界面(UI) 提供了一个 Diagnostic 页面,该页面收集所有节点信息并使用颜色标记它们的状态。此页面可通过 Diagnostic 按钮访问:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

ElasticSearch HQ 的另一个有用功能是能够从 REST 按钮调用 Elasticsearch 的所有 REST 条目。只需单击一个链接,就可以执行相关的 REST 条目:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

ElasticHQ 还提供了一个有用的 REST 接口来测试您的查询:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

对于每个 ElasticSearch 用户来说,ElasticSearch HQ 是一个很好的 UI,它提供了许多有助于 Elasticsearch 日常维护和监控的功能。

Installing Kibana

最著名的 Elasticsearch 接口是 Kibana;从 Elasticsearch 版本 7.x 开始,它们共享相同的版本号。 Kibana 是一个开源的可插拔接口,可免费与 Elasticsearch 一起使用。它提供数据可视化,并且可以使用名为 X-Pack 的商业产品进行扩展,该产品提供安全性、图形功能和集群监控。

在本章中,我们将主要介绍 Kibana 开源组件。带有 X-Pack 的 Kibana 提供了很多功能,由于这些功能超出了本书的范围,我建议您查找与 Kibana 相关的书籍,以获得对所有 Kibana 功能的完整描述。

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch recipe in 第 1 章 开始。  ;

如果您使用 Docker Compose 进行安装,它位于 ch01 目录中,则无需手动安装。

Kibana 版本必须与 Elasticsearch 的版本相同,因此如果您更新 Elasticsearch 集群,那么最好也更新 Kibana 节点。

How to do it...

要安装 Kibana,我们将执行以下步骤:

  1. Download a binary version of the Elasticsearch website and unpack it. For Linux, the commands are as follows:
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.0.0-beta1-linux-x86_64.tar.gz
tar xfvz kibana-7.0.0-beta1-linux-x86_64.tar.gz
  1. On macOSX, you can install Kibana using the following command:
brew install kibana
  1. If Kibana or X-Pack is hard to get ready, then there is a Docker image that you can use to simplify the process (this is available at http://elk-docker.readthedocs.io/#installation). Using two commands on Linux, you can have the stack up and running.

How it works...

Kibana 是官方的 Elasticsearch 前端。这是一个开源分析和可视化平台基于 AngularJS,可与 Elasticsearch 配合使用。它由 Node.js 后端网络服务器提供服务。 Kibana 的开发与 Elasticsearch 高度相关,最佳实践是使用与 Elasticsearch 版本一致的 Kibana 版本。

Kibana 允许您在 Elasticsearch 中导航数据并将其组织在实时创建、共享和更新的仪表板中。

设置并启动 Elasticsearch 和 Kibana 后,您可以使用 http://localhost:5601 导航到 Kibana,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

在玩 Kibana 之前,我建议您加载一些数据集,这些数据集在安装中提供。只需点击 Add sample data 磁贴上的 Load a data set and a Kibana dashboard

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

Kibana 安装提供了一些数据示例,您可以开始使用;这些数据集非常方便,因为它们展示了许多高级 Kibana 仪表板功能;只需点击 添加数据来初始化它们。

如果您选择第一个,您将可以访问全功能仪表板,如下所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

在仪表板的左侧,您有导航栏:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

从导航栏中,您可以访问以下图标:

  • Spaces (the green D): This is a way to group your interface in its defined own spaces
  • Discovery: This is used to navigate your data in order to discover information
  • Visualize: This is used to create visualizations that can be used to populate pages
  • Dashboard: This section hosts your Space dashboards
  • Canvas: This section allows you to create pixel art dashboards that are similar to infographics
  • Maps: This section allows you to manage maps
  • Infrastructure: This section allows you to configure an infrastructure that you can later monitor
  • Logs: This section is used to manage logs
  • Application Performance Monitoring (APM): This section is used to create visualizations
  • Uptime: This section is used to manage the uptime of applications
  • Dev Tools: This section contains the dev tool components
  • Management: This section allows you to configure Kibana
  • Monitor: This is used to monitor your node functionalities and the cluster overall
  • Graph: This provides the graph API for Elasticsearch—that is, a graph-based approach for data discovery
  • Watcher: This is a system providing registered queries, which allows you to monitor and keep an alert on your data
  • Reporting: This is a module that is able to create reports from your dashboards

See also

Managing Kibana discovery

Kibana 最受欢迎的方面之一是发现仪表板。这是因为它允许您动态导航数据。随着 Kibana 的发展,发现仪表板中添加了许多新功能,以便您轻松过滤和分析数据。

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch 第 1 章, 开始 此外,还需要一个工作的 Kibana 实例,如本章的 安装 Kibana 配方中所述。

如果您使用过 ch01 目录中提供的Docker Compose,那么一切都应该正确安装。 

How to do it...

为了管理 Kibana 仪表板,我们将执行以下步骤:

  1. We access the Discovery section of Kibana, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

  1. Now, you can play with and analyze your indexed data.

How it works...

发现部分旨在让您探索您的数据。

您可以保存和共享您创建的发现仪表板——然后可以重复使用它来构建其他仪表板。在屏幕中间,您应该能够查看以表格和 JSON 格式提供的文档:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

如您所见,从前面的屏幕截图中,当您将鼠标悬停在某个字段上时,会启用特殊操作:

  • Filter using this value
  • Filter not using this value
  • Toggle column in table
  • Filter for field present (exists query)

有时,您的数据未显示;这主要是因为您选择了错误的日期范围。

您可以从日历下拉菜单中轻松更改它,如下所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

过滤的核心是从搜索框完成的;在这里,您可以提供类似 Google 的语法以便快速搜索您的数据:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

您可以使用以下两个选项添加过滤器:

  • Using the web interface: This is for simple filters. All the fields are available in the drop-down menus; in this way, building the query should be very easy.
  • Using Edit as Query DSL: This allows you to input your complex JSON.

您还可以使用在屏幕左侧选择字段时自动创建的构面创建过滤器:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

对于每个字段,界面都会建议最常用的值,以便轻松地将它们用作过滤器。使用 符号,您可以选择过滤或取消过滤值。

Visualizing data with Kibana

Kibana 允许您创建称为可视化的可重用数据表示。这些是聚合的表示,可用于使用自定义图表为仪表板供电。通常,您可以将可视化视为仪表板的构建块。

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch 第 1 章, 开始  此外,还需要一个工作的 Kibana 实例,如本章的 安装 Kibana配方中所述。

如果您使用过 ch01 目录中提供的Docker Compose,那么一切都应该正确安装。 

How to do it...

要使用 Kibana 创建自定义小部件,我们将执行以下步骤:

  1. We access the Visualize section of Kibana, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

  1. Now, we can choose the visualization that we want to create, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

  1. If we want to create a Tag cloud visualization, then we select it and populate the required fields, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

How it works...

可以在可视化小部件中对聚合和搜索进行分组,这些小部件可以用作创建自定义界面的构建块。

内置的可视化如下:

  • Area chart: This is useful for representing stacked timelines
  • Controls: These are useful for extending filtering
  • Coordinate Map: This is used to manage geodata
  • Data table: This allows you to create a data table using the aggregation results
  • Gauge: This is useful for showing range values
  • Goal: This is useful for showing the number count
  • Heat Map: This shows data in heat maps
  • Horizontal/Vertical bar chart: This is the general purpose bar representation for histograms
  • Line charts: This is useful for representing time-based hits and comparing them
  • Markdown widget: This is useful for displaying explanations or instructions for dashboards
  • Metric: This represents a numeric metric value
  • Pie: This is useful for representing low cardinality values
  • Region Map: This is useful for displaying geographical boxed data
  • Tag cloud: This is useful for representing term values such as tags and labels
  • Time series/ Timelion: This allows you to use Timelion expression language to create time series chart
  • Vega: This is a customizable JavaScript canvas (https://vega.github.io/vega/)
  • Visual Builder: This allows you to create custom visualization using a predefined builder

选择可视化后,左侧会显示一个自定义表单,允许您填充所有必需的值。在右侧,我们使用查询和聚合的结果近乎实时地更新小部件表示。

可视化配置完成后,必须保存它才能用作仪表板中的小部件:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

选择 创建新仪表板后,您可以通过添加已保存的可视化来开始编辑它,如下图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

仪表板顶部菜单允许您执行以下操作:

  • Create a new dashboard starting from scratch using the New menu entry.
  • Save the current dashboard or query giving it a name.
  • Open the dashboards that you have already saved.
  • Share a dashboard or a dashboard snapshot (with the date/time value fixed) using a link.
  • Generate a PDF from the current dashboard using the Reporting menu entry. In order to generate a report, your dashboard must be saved; the reporting entry is available only if X-Pack is activated.
  • If you are using autorefresh dashboards, then you can pause autorefresh using the pause icon. By clicking on the refresh interval, you can change it.
  • Change or define the time interval range by clicking on the time range value.

在内部,Kibana 仪表板存储在 Elasticsearch .kibana 特殊索引中;对于任何类型的异步任务,数据都是从这个索引中读取的。

在这个秘籍中,我们只触及了强大的 Kibana 仪表板的表面。建议大家购买 Kibana 相关的书籍,或者参考 Kibana 的在线文档或视频,因为它是一个功能非常丰富的工具。

Using Kibana Dev tools

Kibana 为开发人员提供了一个非常方便的部分:Dev Tools。在开源版本中,此部分由三个工具组成:

  • Dev-Console: The place where the developer tests and execute commands
  • Search Profiler: A tool that is used to profile queries
  • Grok Debugger: This is useful for debugging Grok regular expressions

Getting ready

您将需要一个正常运行的 Elasticsearch 安装 - 类似于我们在 下载和安装 Elasticsearch 第 1 章开始 span>此外,还需要一个工作的 Kibana 实例,如本章的 安装 Kibana 配方中所述。

如果您使用过 ch01 目录中提供的Docker Compose,那么一切都应该正确安装。 

How to do it...

要使用 Dev-Console,我们将执行以下步骤:

  1. We access the Dev Tools section of Kibana, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

  1. Now we can use the Dev-Console to create, execute, and test queries and other Elasticsearch HTTP APIs that are using it, as shown in the following screenshot:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

How it works...

Kibana Dev-Console 与我们之前提到的 Cerebro 界面非常相似。它允许您通过 http 接口对 Elasticsearch 执行各种 REST API 调用。它可以用于多种目的,包括:

  • Creating complex queries and aggregations: The console interface helps the user by providing code completion and syntax checking during editing.
  • Analyzing the returned results: This is very useful for checking particular aggregation responses or the structure of the API answers.
  • Testing or debugging queries before embedding them in your application code.
  • Executing REST services that are now wrapped in Elasticsearch interfaces, such as repository, snapshot, and restore services.
Kibana Dev-Console's autocompletion of any queries helps users to build complex queries quickly.

There's more...

Kibana Dev Tools 还支持使用 Profiler ;部分深入了解执行特定查询所需的时间。它在 Kibana 的开源部分中可用,如以下屏幕截图所示:

读书笔记《elasticsearch-7-0-cookbook-fourth-edition》用户界面

由于执行带有某种聚合的查询可能非常复杂,并且可能需要大量时间来分析查询,因此这是 Elasticsearch 中用于分析查询执行的最高级接口。