Kibana 简明教程

Kibana - Working With Region Map

通过此可视化,您可以在世界地理地图上看到表示的数据。在本章中,让我们详细了解它。

With this visualization, you see the data represented on the geographical world map. In this chapter, let us see this in detail.

Create Index for Region Map

我们创建一个新索引,以便使用区域地图可视化工具。我们即将上传的数据如下所示 −

We will create a new index to work with region map visualization. The data that we are going to upload is shown here −

{"index":{"_id":1}}
{"country": "China", "population": "1313973713"}
{"index":{"_id":2}}
{"country": "India", "population": "1095351995"}
{"index":{"_id":3}}
{"country": "United States", "population": "298444215"}
{"index":{"_id":4}}
{"country": "Indonesia", "population": "245452739"}
{"index":{"_id":5}}
{"country": "Brazil", "population": "188078227"}
{"index":{"_id":6}}
{"country": "Pakistan", "population": "165803560"}
{"index":{"_id":7}}
{"country": "Bangladesh", "population": "147365352"}
{"index":{"_id":8}}
{"country": "Russia", "population": "142893540"}
{"index":{"_id":9}}
{"country": "Nigeria", "population": "131859731"}
{"index":{"_id":10}}
{"country": "Japan", "population": "127463611"}

请注意,我们将在 dev 工具中使用 _bulk 上载数据。

Note that we will use _bulk upload in dev tools to upload the data.

现在,转到 Kibana Dev 工具并执行以下查询 −

Now, go to Kibana Dev Tools and execute following queries −

PUT /allcountries
{
   "mappings": {
      "_doc": {
         "properties": {
            "country": {"type": "keyword"},
               "population": {"type": "integer"}
         }
      }
   }
}
POST /allcountries/_doc/_bulk?refresh
{"index":{"_id":1}}
{"country": "China", "population": "1313973713"}
{"index":{"_id":2}}
{"country": "India", "population": "1095351995"}
{"index":{"_id":3}}
{"country": "United States", "population": "298444215"}
{"index":{"_id":4}}
{"country": "Indonesia", "population": "245452739"}
{"index":{"_id":5}}
{"country": "Brazil", "population": "188078227"}
{"index":{"_id":6}}
{"country": "Pakistan", "population": "165803560"}
{"index":{"_id":7}}
{"country": "Bangladesh", "population": "147365352"}
{"index":{"_id":8}}
{"country": "Russia", "population": "142893540"}
{"index":{"_id":9}}
{"country": "Nigeria", "population": "131859731"}
{"index":{"_id":10}}
{"country": "Japan", "population": "127463611"}

接下来,让我们创建索引 allcountries。我们指定的国家字段类型为 keyword

Next, let us create index allcountries. We have specified the country field type as keyword

PUT /allcountries
{
   "mappings": {
      "_doc": {
         "properties": {
            "country": {"type": "keyword"},
            "population": {"type": "integer"}
         }
      }
   }
}

Note − 为了使用区域地图,我们需要指定字段类型,该字段类型应与聚合一起使用,且类型为关键字。

Note − To work with region maps we need to specify the field type to be used with aggregation as type as keyword.

kibana region maps

完成后,使用 _bulk 命令上传数据。

Once done, upload the data using _bulk command.

kibana using bulk

现在我们将创建索引模式。转到 Kibana 管理选项卡并选择创建索引模式。

We will now create index pattern. Go to Kibana Management tab and select create index pattern.

kibana management tab

下面将显示来自 allcountries 索引的字段。

Here are the fields displayed from allcountries index.

displayed allcountries index

Getting Started with Region Maps

现在,我们使用区域地图创建可视化效果。转到可视化效果并选择区域地图。

We will now create the visualization using Region Maps. Go to Visualization and select Region Maps.

visualization using region maps

完成后,选择索引 allcountries 并继续。

Once done select index as allcountries and proceed.

按照以下所示选择聚合指标和存储桶指标 −

Select Aggregation Metrics and Bucket Metrics as shown below −

select aggregation metrics
bucket metrics

在此,我们选择字段为国家,因为我想在世界地图上显示与此相同的字段。

Here we have selected field as country, as i want to show the same on the world map.

Vector Map and Join Field for Region Map

对于区域地图,还需要选择选项选项卡,如下所示 −

For region maps we need to also select Option tabs as shown below −

vector map

此选项选项卡具有图层设置配置,需要这些配置将数据标识到世界地图中。

The options tab has Layer Settings configuration which are required to plot the data on the world map.

矢量地图具有以下选项 −

A Vector Map has the following options −

vector map options

在此,我们选择世界各国,因为我具有各个国家地区的数据。

Here we will select world countries as i have countries data.

Join Field 具有以下详细信息 −

The Join Field has following details −

join field

在我们索引中,我们有国家名称,因此我们将选择国家名称。

In our index we have the country name, so we will select country name.

在样式设置中,您可以选择国家/地区要显示的颜色 −

In Style settings you can choose the color to be displayed for the countries −

style settings

我们选择红色。我们不会触及其他详细信息。

We will select Reds. We will not touch the rest of the details.

现在,单击“分析”按钮,查看如下显示在地图上的国家地区详细信息 −

Now,click on Analyze button to see the details of the countries plotted on the world map as shown below −

click analyze button

Self-hosted Vector Map and Join Field in Kibana

您还可以为矢量地图和联接字段添加您自己的 Kibana 设置。为此,从 Kibana 配置文件夹中转至 kibana.yml,并添加以下详细信息 −

You can also add your own Kibana settings for vector map and join field. To do that go to kibana.yml from the kibana config folder and add the following details −

regionmap:
   includeElasticMapsService: false
   layers:
      - name: "Countries Data"
      url: "http://localhost/kibana/worldcountries.geojson"
      attribution: "INRAP"
      fields:
         - name: "Country"
         description: "country names"

选项选项卡中的矢量地图将使用上述数据填充,而不是默认数据。请注意,必须启用给出的 URL 的 CORS,以便 Kibana 可以下载它。所使用的 JSON 文件应使坐标连续。例如:−

The vector map from options tab will have the above data populated instead of the default one. Please note the URL given has to be CORS enabled so that Kibana can download the same. The json file used should be in such a way that the coordinates are in continuation. For example −

当 region-map 矢量地图详细信息自托管时,选项选项卡如下所示 −

The options tab when region-map vector map details are self-hosted is shown below −

vector map details