Process and analyze data with Transforms
The Transforms feature in Elasticsearch lets you preprocess, aggregate, and transform data. It creates a new destination index without affecting the raw data, making it ideal for analysis and visualization. In this tutorial, you will use Transforms to process NBA shot data and view the results.
Prerequisites
-
Download the sample data. This tutorial uses the Kaggle dataset
NBA shot logs. It includes fields such as shot time, shooter, shot location, the closest defender, and the defender's distance from the shooter. To download the dataset, see shot_logs.csv. -
Create an Alibaba Cloud Elasticsearch instance. For more information, see Create an Alibaba Cloud Elasticsearch instance. This tutorial uses an Elasticsearch V7.10.0 instance.
NoteElasticsearch V8.5 instances are not supported.
-
Log on to the Kibana console. For more information, see Log on to the Kibana console.
-
Import the
shot_logsdata and create an index.-
In the upper-left corner of the Kibana page, choose .
-
Click the Data Visualizer tab.
-
In the Import data area, click Upload file.
-
Click the
icon. -
Select the
shot_logsfile. -
In the lower-right corner of the page, click Import.
-
On the Simple tab, set Index name to
nba_shot_logsand select Create index pattern. -
Click Import.
After a successful import, the following summary is displayed:
-
Index:
nba_short_logs -
Index pattern:
nba_short_logs -
Ingest pipeline:
nba_short_logs-pipeline -
Documents ingested: 128069
-
-
Procedure
This tutorial describes three methods to transform and view data.
Method 1: Create a transform in Kibana
-
In the upper-left corner of the Kibana page, choose .
-
In the left-side navigation pane, click .
-
Click Create your first transform.
-
Select the
nba_shot_logsindex. -
In the Configuration section, set Group by to histogram(GAME_ID), and set Aggregations to DRIBBLES.sum, DRIBBLES.avg, and DRIBBLES.max.
Note-
Groups data by game ID.
-
DRIBBLES.sum: the total number of dribbles by all players in each game.
-
DRIBBLES.avg: the average number of dribbles per player in each game.
-
DRIBBLES.max: The maximum number of dribbles before a shot in each game.
-
-
In the lower-right corner of the Configuration section, click Next.
-
In the Transform details section, specify the Transform ID and destination index, and click Next.
-
In the Create section, click Create and start.
NoteThe transform is complete when the progress bar reaches 100%.
-
Click Discover to view the data in the destination index.
The Discover page displays the destination index
test_nba_shot_logswith 91 hits. Each document contains the aggregation fieldsDRIBBLES.avg,DRIBBLES.max,DRIBBLES.sum, and the group-by fieldGAME_ID.
Method 2: Create and preview with API
-
In the upper-left corner of the Kibana page, choose .
-
On the Console tab, run the following command to create a transform.
PUT _transform/test2_nba_shot_logs { "source": { "index": "nba_shot_logs" }, "dest" : { "index" : "test2_nba_shot_logs" }, "pivot": { "group_by": { "game_id": { "terms": { "field": "GAME_ID" }} }, "aggregations": { "dribbles_sum": { "sum": { "field": "DRIBBLES" }}, "dribbles_avg": { "avg": { "field": "DRIBBLES" }}, "dribbles_max": { "max": { "field": "DRIBBLES" }} } } } -
Run the following command to preview the transformed data.
POST _transform/_preview { "source": { "index": "nba_shot_logs" }, "dest" : { "index" : "test2_nba_shot_logs" }, "pivot": { "group_by": { "game_id": { "terms": { "field": "GAME_ID" }} }, "aggregations": { "dribbles_sum": { "sum": { "field": "DRIBBLES" }}, "dribbles_avg": { "avg": { "field": "DRIBBLES" }}, "dribbles_max": { "max": { "field": "DRIBBLES" }} } } }
-
Method 3: Create by API, view in Discover
-
Create and start the transform.
-
In the upper-left corner of the Kibana page, choose .
-
On the Console tab, run the following command to create the transform.
PUT _transform/test2_nba_shot_logs { "source": { "index": "nba_shot_logs" }, "dest" : { "index" : "test2_nba_shot_logs" }, "pivot": { "group_by": { "game_id": { "terms": { "field": "GAME_ID" }} }, "aggregations": { "dribbles_sum": { "sum": { "field": "DRIBBLES" }}, "dribbles_avg": { "avg": { "field": "DRIBBLES" }}, "dribbles_max": { "max": { "field": "DRIBBLES" }} } } } -
Start the transform.
POST _transform/test2_nba_shot_logs/_startNoteTransforms are stopped by default.
-
-
Create an index pattern.
NoteYou must create an index pattern to view the data in Discover.
-
In the upper-left corner of the Kibana page, choose .
-
In the left-side navigation pane, click .
-
In the upper-right corner of the page, click Create index pattern.
-
For Index pattern name, enter the destination index, test2_nba_shot_logs, and click Next step.
-
Click Create index pattern.
-
-
View data in Discover.
-
In the upper-left corner of the Kibana page, choose .
-
Select the destination index to view the transformed data.
-
> Kibana > Machine Learning