简体   繁体   English

使用Logstash JDBC插件在Elasticsearch中添加标签

[英]Add tags in Elasticsearch using logstash jdbc plugin

Suppose we have 2 table 假设我们有2张桌子

1) Customer (CustID, Name) 1)客户(客户ID,姓名)

2) Purchases (Cust_ID, Purchase_ID) 2)购买(客户ID,Purchase_ID)

There is one to many (1:n) relation between (1) & (2). (1)和(2)之间存在一对多(1:n)关系。

Now using logstash I want to insert this data from sql into elasticsearch. 现在使用logstash,我想将此数据从sql插入elasticsearch。 The problem is if I take join of two tables then it will insert multiple rows/json records for a single customer. 问题是,如果我将两个表连接起来,那么它将为单个客户插入多行/ json记录。 I wish to insert data as follows. 我希望如下插入数据。

{
Cust_ID : 101,
Purchase_ID : [ 1001, 2003, 20006]
}

but it comes as 但它来了

{
Cust_ID : 101,
Purchase_ID : 1001
},
{
Cust_ID : 101,
Purchase_ID : 2003
}

I found the link https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html useful. 我发现链接https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html很有用。 But it doesn't solve my problem. 但这不能解决我的问题。

Every row your SQL query returns becomes a document in Elasticsearch. SQL查询返回的每一行都将成为Elasticsearch中的一个文档。 So, change your query to return the row you want. 因此,更改查询以返回所需的行。 It may be that you need to concatenate your purchaseIds into one field, and then use logstash's mutate->split to turn them into an array. 可能是您需要将purchaseIds连接到一个字段中,然后使用logstash的mutate-> split将它们转换为数组。

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

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