利用logstash-output-jdbc从mysql导入数据到es中,如何构建多级节点的JSON
匿名 | 发布于2017年06月17日 | 阅读数:5303
请教:利用logstash-output-jdbc从mysql导入数据到es中,如何构建多级节点的JSON. 如产品表,需要关联产品品牌,产品供应商。
SQL语句:SELECT
product.id,
product.code,
product.name AS name,/**产品名称**/
provider.id AS providerId,/**供应商id**/
provider.CODE AS providerCode,/**供应商编号**/
provider.NAME AS providerName,/**供应商名称**/
brand.id AS brandId,/**品牌id**/
brand.NAME AS brandName/**品牌名称**/
FROM
t_product product
LEFT JOIN t_product_provider provider ON product.provider_id = provider.id
LEFT JOIN t_product_brand brand ON product.brand_id = brand.id
问题:如何生成类似如下的JSON对象
{"id" : "1",
"code":"001" ,
"name" :"####" ,
"brand":{ //品牌属性
"id": "##",
"name": "##"
},
"provider":{ //供应商属性
"id": "##",
"code": "##",
"name": "##"
}
}
SQL语句:SELECT
product.id,
product.code,
product.name AS name,/**产品名称**/
provider.id AS providerId,/**供应商id**/
provider.CODE AS providerCode,/**供应商编号**/
provider.NAME AS providerName,/**供应商名称**/
brand.id AS brandId,/**品牌id**/
brand.NAME AS brandName/**品牌名称**/
FROM
t_product product
LEFT JOIN t_product_provider provider ON product.provider_id = provider.id
LEFT JOIN t_product_brand brand ON product.brand_id = brand.id
问题:如何生成类似如下的JSON对象
{"id" : "1",
"code":"001" ,
"name" :"####" ,
"brand":{ //品牌属性
"id": "##",
"name": "##"
},
"provider":{ //供应商属性
"id": "##",
"code": "##",
"name": "##"
}
}
2 个回复
NovemberRain_Jack
赞同来自:
如果使用nested方式的话,就需要用到aggregate filter 官网有很具体的例子
匿名用户
赞同来自:
利用logstash-input-jdbc从mysql导入数据到es中,构建json嵌套解决方法:
1: 1对1的场景:
在过滤器中处理:
filter {
mutate {
add_field => {
"[brand][id]" => "%{brand_id}"
"[brand][name]" => "%{brand_name}"
"[provider][id]" => "%{provider_id}"
"[provider]