找到问题的解决办法了么?

logstash应该如何同步到List形式的ES对象字段呢

Logstash | 作者 EricTowns | 发布于2020年03月03日 | 阅读数:2921

请教各位老哥,小弟用logstash从PG数据库中同步数据到ES(logstash和ES版本都是6.5.2),需要同步的数据如图


znwd问题2.png


我想把attachmentName和attachmentUrl同步到ES的attachment对象字段中,索引的mappings为
...
"attachment": {
"properties": {
"attachmentName": {
"type": "text",
"analyzer": "ik_smart",
"fields": {
"max": {
"type": "text",
"analyzer": "ik_max_word"
},
"keyword": {
"type": "keyword"
},
"ngram": {
"analyzer": "ngram",
"type": "text"
}
}
},
"attachmentUrl": {
"type": "keyword"
}
}
},
"createTime": {
"type": "date"
},
"updateTime": {
"type": "date"
},
...
想要同步后的效果:
"_source": {
"questionContent": "尝试对象的输入",
"answerContent": "try it again",
"firstCategory": "一级类目",
"secondCategory": "二级类目",
"appOuterName": "对外名称",
"appUrl": "www.baihe.com",
"appWay": 2,
"attachment": [
{
"attachmentName": "照片1",
"attachmentUrl": "www.baidu.com"
}
,
{
"attachmentName": "照片2",
"attachmentUrl": "www.sougou.com"
}
],
"isDel": 0
}

 
已邀请:

medcl - 今晚打老虎。

赞同来自: laoyang360 EricTowns tacsklet

这里主要是看如何合并多条记录到一个文档里面,首先要看这些记录是不是都是静态的,如果有更新则还要考虑更新的问题。有多种实现方式:
 
一种是在 Logstash 里面按主 key 排序,根据主 key 在内存里面合并成一个完整的对象,判断出现新的 key 的时候,发送到 Output 里面。具体可以参照 Aggregate Filter的用法:https://www.elastic.co/guide/e ... .html
 
另外一种则是用 es 端来做 upsert 聚合,具体参照我的这篇文章:https://mp.weixin.qq.com/s/H1I3EeXEaOWpEBSR_SRBow,注意这种方式会对 Elasticsearch 造成额外的更新压力,适合数据量不大的场景。
 
如果数据量很大,还是建议自己写程序来合并封装,要更加灵活和可控,性能也会好一点。

要回复问题请先登录注册