Synchronize MaxCompute data to Elasticsearch with Logstash
You can use Alibaba Cloud Logstash with the logstash-input-maxcompute plugin to synchronize data from offline tables in MaxCompute to Alibaba Cloud Elasticsearch. This topic describes how to configure a pipeline.
Prerequisites
Before you begin, complete the following tasks:
Activate MaxCompute, create a project and a table, and import data into the table.
For more information, see the Preparations and Quick Start topics in the MaxCompute documentation.
Create an Alibaba Cloud Logstash instance and install the logstash-input-maxcompute plugin.
For more information, see Step 2: Create an Alibaba Cloud Logstash instance and Install or uninstall plug-ins.
Create a destination Alibaba Cloud Elasticsearch instance and enable its automatic index creation feature.
For more information, see Create an Alibaba Cloud Elasticsearch instance and Quick access and configuration. This topic uses an instance of version 6.7.0 as an example.
Ensure that MaxCompute, the Alibaba Cloud Logstash instance, and the Alibaba Cloud Elasticsearch instance can communicate with each other. They must be in the same Virtual Private Cloud (VPC).
NoteYou can also use services on the public network by configuring a NAT Gateway to connect to the public network. For more information, see Configure a NAT Gateway for public data transfer.
Configure a Logstash pipeline
Go to the Logstash Clusters page.
Navigate to the target cluster.
In the top navigation bar, select the region where the cluster resides.
On the Logstash Clusters page, find the cluster and click its ID.
In the left-side navigation pane, click Pipeline Management.
-
Click Create Pipeline.
On the Create Pipeline Task page, enter a pipeline ID and configure the pipeline.
The following code provides an example configuration.
input { maxcompute { access_id => "yourAccessKeyID" access_key => "yourAccessKeySecret" endpoint => "http://service.cn-hangzhou.maxcompute.aliyun-inc.com/api" project_name => "your_project_name" table_name => "your_table_name" partition => "sale_date='201911', region='hangzhou'" thread_num => 1 dirty_data_file => "/ssd/1/<your_logstash_instance_id>/logstash/data/failed_records.txt" } } output { elasticsearch { hosts => ["http://es-cn-abcde12345.elasticsearch.aliyuncs.com:9200"] index => "your_index_name" user => "elastic" password => "your_password" } }Table 1. Input parameters
Parameter
Type
Required
Description
access_id
string
Yes
Your Alibaba Cloud AccessKey ID.
access_key
string
Yes
Your Alibaba Cloud AccessKey Secret.
endpoint
string
Yes
The MaxCompute endpoint in your region. For more information, see VPC Endpoint.
project_name
string
Yes
The name of your MaxCompute project.
table_name
string
Yes
The name of your MaxCompute table.
partition
string
Yes
The partition key. For a partitioned table, you must specify the partition. For example:
sale_date='201911',region='hangzhou'.thread_num
number
Yes
The number of threads. The default value is 1.
dirty_data_file
string
Yes
The path to a file for logging failed records.
NoteThe file must be located in the
/ssd/1/<your_logstash_instance_id>/logstash/data/directory.ImportantThe preceding configuration is for testing only. For production environments, configure the pipeline based on your business requirements. For other configuration options supported by the input plugin, see the logstash-input-maxcompute plugin documentation.
The logstash-input-maxcompute plugin performs a full data synchronization from MaxCompute to Alibaba Cloud Elasticsearch.
For more information about pipeline configuration, see Logstash configuration files.
-
Click Next step and configure the pipeline parameters.
Parameter
Description
Pipeline Workers
Number of worker threads for the filter and output stages. Increase this value if events are backlogged or CPU is underutilized. Default: the number of CPU cores.
Pipeline Batch Size
Maximum events a worker collects before executing filters and outputs. Larger batches increase memory usage and may require a larger JVM heap size (LS_HEAP_SIZE). Default: 125.
Pipeline Batch Delay
Wait time in milliseconds before dispatching an undersized batch to a worker thread. Default: 50 ms.
Queue Type
Internal queuing model for event buffering between stages. Valid values:
-
MEMORY: Default. Uses an in-memory queue.
-
PERSISTED: A disk-based persistent queue.
Queue Max Bytes
The maximum amount of data the queue can store, in
MB. The value must be an integer from1to253-1. Default value:1024.NoteMake sure that this value is less than your total disk capacity.
Queue Checkpoint Writes
Maximum events written before a checkpoint is forced (persistent queue only). 0 means no limit. Default: 1024.
WarningSaving and deploying the configuration triggers an instance restart. Proceed only when this will not affect your business.
-
-
Click Save or Save and Deploy.
-
Save: Saves the pipeline configuration but does not apply it. After saving, you are returned to the Pipelines page. In the Pipelines section, you can click Deploy Now in the Actions column to restart the instance and apply the configuration.
-
Save and Deploy: Saves and deploys the configuration, restarting the instance to apply the changes.
-
Verify the results
Log on to the Kibana console of your destination Alibaba Cloud Elasticsearch instance.
For more information, see Log on to the Kibana console.
In the left-side navigation pane, click Dev Tools.
In the Console, run the following command to view the synchronized data.
GET /your_index_name/_searchA successful response is shown below.
{ "took" : 6, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 2, "max_score" : 1.0, "hits" : [ { "_index" : "odps_index", "_type" : "doc", "_id" : "AT2dDxxxglu", "_score" : 1.0, "_source" : { "shop_name" : "shopy", "customer_id" : "y_id", "@timestamp" : "2019-12-16T07:30:15.208Z", "@version" : "1", "total_price" : 200.0 } }, { "_index" : "odps_index", "_type" : "doc", "_id" : "vtCdDxxxIT", "_score" : 1.0, "_source" : { "shop_name" : "shopy", "customer_id" : "y_id", "@timestamp" : "2019-12-16T07:30:15.206Z", "@version" : "1", "total_price" : 200.0 } } ] } }NoteIf the command fails, check the logs on the Log Query page for troubleshooting. For more information, see Query Logs.
Go to the Monitoring page and click Indices.
On the Indices page, view the synchronized index and the number of documents it contains.
The
odps_indexindex status is Green with a Document Count of 4.