我必须建立一个价格比较系统。我的想法是使用Elasticsearch来构建。现在我遇到了这个问题。如何汇总每个产品的卖方价格。
例如,请参阅此屏幕截图:

假设我有一个简单的映射:
products: {
product: {
properties: {
id: {
type: "long"
},
name: {
type: "string"
},
....
sellers: {
dynamic: "true",
properties: {
sellerId: {
type: "long"
},
price: {
type: "float"
}
}
}
}
}
}我是否可以对每个产品的价格(最低、最高和卖家计数)进行汇总或分面?
或者,有没有办法用亲子关系来构建这个东西?
发布于 2014-03-29 03:26:27
假设你使用的是1.0而不是0.90,那么你可以使用min,max和value_count聚合很容易做到这一点。
{
"query": {
"match": {
"name": "item1"
}
},
"aggs": {
"Min": {
"min": {
"field": "sellers.price"
}
},
"Max": {
"max": {
"field": "sellers.price"
}
},
"SellerCount": {
"value_count": {
"field": "sellers.sellerId"
}
}
}
}或者,您可以使用子聚合来返回每个产品的信息,而不是特定的产品。
{
"aggs": {
"Products": {
"terms": {
"field": "name",
"size": 10
},
"aggs": {
"Min": {
"min": {
"field": "sellers.price"
}
},
"Max": {
"max": {
"field": "sellers.price"
}
},
"SellerCount": {
"value_count": {
"field": "sellers.sellerId"
}
}
}
}
}
}https://stackoverflow.com/questions/22696958
复制相似问题