那是一个很好的开始!
我一定会把所有内容弄平(例如,反规范化),并拿出如下产品文档。这样,您只需
flags为每个产品创建一个数组即可摆脱产品和标志之间的N:M关系。因此,查询这些标志将更加容易。
{ "id": "00c8234d71c4e94f725cd432ebc04", "title": "Alpha", "price": 589.0, "flags": ["Sellout", "Top Product"]}{ "id": "018357657529fef056cf396626812", "title": "Beta", "price": 355.0, "flags": ["Discount"]}{ "id": "01a2c32ceeff0fc6b7dd4fc4302ab", "title": "Gamma", "price": 0.0, "flags": ["Discount"]}
产品映射类型如下所示:
PUT products{ "mappings": { "product": { "properties": { "id": { "type": "string", "index": "not_analyzed" }, "title": { "type": "string" }, "price": { "type": "double", "null_value": 0.0 }, "flags": { "type": "string", "index": "not_analyzed" } } } }}
由于已经有logstash
jdbc输入,因此您所缺少的只是用于提取产品和相关标志的正确SQL查询。
SELECt p.Id as id, p.Title as title, p.Price as price, GROUP_CONCAt(f.Title) as flags FROM Products p JOIN flagsProducts fp ON fp.ProductId = p.Id JOIN Flags f ON fp.FlagId = f.idGROUP BY p.Id
这将使您像这样的行:
+-------------------------------+-------+-------+---------------------+| id | title | price | flags |+-------------------------------+-------+-------+---------------------+| 00c8234d71c4e94f725cd432ebc04 | Alpha | 589 | Sellout,Top product || 018357657529fef056cf396626812 | Beta | 355 | Discount || 01a2c32ceeff0fc6b7dd4fc4302ab | Gamma | 0 | Discount |+-------------------------------+-------+-------+---------------------+
然后,您可以使用Logstash过滤器将拆分
flags为一个数组,然后开始使用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)