自从更新到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": []
}
}
从2.3升级到6.4是一个非常巨大的升级,并且发生了很多变化。如果您在某些时候有时间,我强烈推荐Elastic文档的Breaking Changes部分。它至少会给你一个大变化的粗略概念。至少查看主要版本5和6。
现在,我认为5.0版本的映射发生了变化。一些限制,默认行为的一些更改。我想在你的情况下,你正在使用动态映射;意思是你自己没有指定映射?
如果我正确地读取了您的映射,那么您想要引用聚合中的字段measurements.keyword
和measurements.part_type.keyword
字段。未指定raw
字段,可能引用2.x中的旧默认值。
这是最可能的原因:5.0 mapping changes