【发布时间】:2019-09-22 01:51:38
【问题描述】:
我在产品文档中嵌入产品属性,我想做一个聚合,当属性的值大于 0 时返回属性名称。
我应该如何编写查询?
================================================ ========
ElasticSearch 中存储的数据示例:
从以下数据集中,我预计结果是:["Sugar", "Fat"] 因为没有产品包含水
[{
name: "Product1",
price: 12.0,
properties: [
{
group: "Product Composition",
name: "Sugar",
value: 1
},
{
group: "Product Composition",
name: "Fat",
value: 2
},
{
group: "Product Composition",
name: "Water",
value: 0
},
{
group: "Packaging",
name: "Size",
value: "Big"
}
]
}, {
name: "Product2",
price: 11.0,
properties: [
{
group: "Product Composition",
name: "Sugar",
value: 0
},
{
group: "Product Composition",
name: "Fat",
value: 2
},
{
group: "Product Composition",
name: "Water",
value: 0
},
{
group: "Packaging",
name: "Size",
value: "Small"
}
]
}]
======== 索引映射 ========
{
"test_products": {
"mappings": {
"product": {
"dynamic_templates": [
{
"template_1": {
"path_match": "properties.value",
"match_mapping_type": "double",
"mapping": {
"scaling_factor": 100,
"type": "scaled_float"
}
}
},
{
"template_2": {
"path_match": "properties.value",
"match_mapping_type": "string",
"mapping": {
"fields": {
"raw": {
"ignore_above": 100,
"type": "keyword"
}
},
"type": "text"
}
}
}
],
"properties": {
"name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"price": {
"type": "double"
},
"properties": {
"type": "nested",
"properties": {
"group": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"value": {
"type": "text"
}
}
}
}
}
}
}
}
【问题讨论】:
-
请分享您的相关数据映射,以便我可以在我的测试集群中进行模拟。
-
嗨@apt-get_instal_skill,很抱歉回复晚了,我在问题中添加了索引映射。
标签: elasticsearch nested elasticsearch-aggregation