简体   繁体   English

使用 Logstash 使用单个 Elasticsearch 索引从两个 mysql 表同步数据

[英]Sync data from two mysql tables with single Elasticsearch Index using Logstash

I have two mysql tables that I want to save into a single Elastic index.我有两个 mysql 表,我想将它们保存到单个弹性索引中。

Table 1: Product has id , name ... etc.表 1: Productidname ...等。

Table 2: ProductWarehouse has productId , warehouseId , qtyAvailable ... etc表 2: ProductWarehouseproductIdwarehouseIdqtyAvailable ...等

Product one-to-many ProductWarehouse Product一对多ProductWarehouse

My question is, how can I save ProductWarehouse records for each product as an array?我的问题是,如何将每个productProductWarehouse记录保存为数组?

If ProductWarehouse was modified, how to reflect that on the Elastic index?如果ProductWarehouse被修改了,如何在 Elastic 索引上体现出来?

What is the best practice?最佳做法是什么?

the Product index in Elastic should look like: Elastic 中的产品索引应如下所示:

{
 "id",
 "name": ...,
 "warehouses": [
   {"warehouseId": 1, "qtyAvailable": 3},
   {"warehouseId": 10, "qtyAvailable": 30}
 ]
}

My suggestion is to create a MySQL view of the structure you need: Product joins with ProductWarehouse.我的建议是创建您需要的结构的 MySQL 视图:产品与 ProductWarehouse 连接。 This view just to use in Sync and then make the Sync from this view to ElasticSearch using Logstash.此视图仅用于同步,然后使用 Logstash 将此视图同步到 ElasticSearch。

Then you can use the ElasticSearsh Index as this structure:然后你可以使用 ElasticSearsh 索引作为这个结构:

{
 "id",
 "name": ...,
 "warehouses": 1
}
{
 "id",
 "name": ...,
 "warehouses": 3
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM