[英]Elasticsearch nested aggregation
Example例子
PRODUCT 1
"attributes_list" : {
"src1" : [
{
"aname" : "Manufacturer Standard Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "red"
},
{
"aname" : "Detailed Description",
"avalue" : "Pre-Biased Bipolar
},
{
"aname" : "DC Current Gain (hFE) (Min) @ Ic, Vce",
"avalue" : "100 @ 10mA, 5V"
},
{
"aname" : "Transistor Type",
"avalue" : "2 NPN - Pre-Biased (Dual)"
},
{
"aname" : "Mounting Type",
"avalue" : "Surface Mount"
}
],
"src2" : [
{
"aname" : "Manufacturer Standard Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "red"
},
{
"aname" : "Detailed Description",
"avalue" : "Pre-Biased Bipolar
}
]
},
PRODUCT 2-------------
"attributes_list" : {
"src1" : [
{
"aname" : "Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "green"
},
{
"aname" : "Description",
"avalue" : "Pre-Biased Bipolar
},
{
"aname" : "DC Current Gain (hFE) ",
"avalue" : "100 @ 10mA, 5V"
},
{
"aname" : "Transistor",
"avalue" : "2 NPN - Pre-Biased (Dual)"
},
{
"aname" : "Type",
"avalue" : "Surface Mount"
}
],
"src2" : [
{
"aname" : "Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "green"
},
{
"aname" : "Description",
"avalue" : "Pre-Biased Bipolar
}
]
},
How to create mapping for this kind of field data?如何为这种字段数据创建映射? We need to achieve something like.. For products filters we need to show the aggregation
我们需要实现类似......对于产品过滤器,我们需要显示聚合
In the above 2 products the aname COLOR is available on both products attributes list.在上述 2 种产品中,两个产品属性列表中都提供了名称颜色。 We need to get color (doc_count=2) etc to list the most common attributes for filtering.
我们需要获取颜色(doc_count=2)等来列出最常见的过滤属性。
In my opinion, your data is certainly of type nested
.在我看来,您的数据肯定是类型
nested
。 In Elasticsearch, there is no specific data type for a list, so in general, the first item in the list will defined its mapping type, if you did not explicitly specify the mapping.在 Elasticsearch 中,列表没有特定的数据类型,所以一般情况下,如果您没有明确指定映射,列表中的第一项将定义其映射类型。
{
"mappings": {
"properties": {
"attributes_list": {
"type": "nested",
"properties": {
"src1": {
"type": "nested",
"properties": {
"aname": {
"type": "keyword"
},
"avalue": {
"type": "text"
}
}
},
"src2": {
"type": "nested",
"properties": {
"aname": {
"type": "keyword"
},
"avalue": {
"type": "text"
}
}
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.