我有以下产品文档:
curl -XPOST -H 'Content-Type: application/json' "http://localhost:9200/test/_bulk?pretty" -d'
{"index":{"_index":"test","_type":"product"}}
{"id":"1", "price": "260" }
{"index":{"_index":"test","_type":"product"}}
{"id":"2", "price": "420" }
{"index":{"_index":"test","_type":"product"}}
{"id":"3", "price": "250" }
这些折扣文件:
curl -XPOST -H 'Content-Type: application/json' "http://localhost:9200/test/_bulk?pretty" -d'
{"index":{"_index":"test","_type":"discount"}}
{"product_id":"1", "group_id": 12, "percent": "50" }
{"index":{"_index":"test","_type":"discount"}}
{"product_id":"1", "group_id": 15, "percent": "20" }
{"index":{"_index":"test","_type":"discount"}}
{"product_id":"3", "group_id": 12, "percent": "10" }
我需要通过product_id
和group_id
键加入这两个文档。
在mysql数据库中将如下所示:
SELECT p.id, IF(d.percent > 0, p.price - (d.percent*p.price/100), p.price) price
FROM product p
LEFT JOIN discount d ON p.id=d.product_id AND d.group_id=12
WHERE IF(d.percent > 0, p.price - (d.percent*p.price/100), p.price) < 210
该查询的结果将只有一行:
id => 1
price => 130
可以在elasticsearch中做吗?