自从更新到ES 6.4以来,我的聚合返回了空存储桶。这就是聚合的样子:
"measurements": {
"terms": {
// This decides the number of buckets
"size": 20,
"field": "measurements.raw"
}
},
"part_type": {
"terms": {
"size": 20,
"field": "part_type.raw"
}
}
这曾经很完美。这部分的映射为:
"parts": {
"properties": {
"measurements": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"part_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
不知何故,存储桶仍然是空数组,我似乎无法弄清楚为什么。现在查询中有错误。
从查询搜索返回的示例数据为:
{
"_index": "certificates",
"_type": "certificate",
"_id": "56a74f7c5dee788d0c3bc86f",
"_score": 1,
"_source": {
"certificate_number": "A10288",
"certificate_type": "3.1B",
"norm": "",
"material_quality": "904L",
"manufacturer": "BLABLA",
"bb_code": "xxx",
"attached_file": {
"originalname": "",
"filename": ""
},
"parts": [
{
"measurements": "Ø73.02x5.16",
"charge_number": "442665",
"probe_number": "",
"part_type": "ELBOW",
"comment": "",
"factory_code": "",
"_id": "56a74f7c5dee788d0c3bc870",
"mcl_order_number": [
{
"number": "43.9.069"
}
]
}
],
"created_by": {
"user_name": "System import"
},
"__v": 0
}
}
我已经尝试根据6.4文档重写它,使其看起来像这样:
aggregations = {
"parts": {
"terms": {"field": "parts"},
"aggs": {
"measurements": {
"terms": {"field": "parts.measurements.raw"}
},
"part_type": {
"terms": {"field": "parts.part_type.raw"}
},
}
}
}
这将返回以下内容:
"aggregations": {
"parts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
答案 0 :(得分:0)
从2.3升级到6.4是一个巨大的升级,并且发生了很多变化。如果您有时间,我强烈建议您使用Elastic文档的Breaking Changes部分。至少会给您带来大变化的大致思路。至少检查主要版本5和6。
现在,我认为从5.0开始,映射发生了变化。一些限制,一些默认行为的变化。我猜在您的情况下,您正在使用动态映射。意味着您没有自己指定映射?
如果我正确阅读了您的映射,那么您想引用聚合中的measurements.keyword
和measurements.part_type.keyword
字段。 raw
字段未指定,可能是指2.x中的旧默认值。
最可能的原因是:5.0 mapping changes