弹性搜索聚合桶保持为空

Elastic search aggregation buckets remain empty

自更新到 ES 6.4 以来,我的聚合 return 空桶。这是聚合的样子:

"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
                                }
                            }
                },
 },

不知何故,桶仍然是空的数组,我似乎无法弄清楚为什么。查询中现在有错误。

来自查询搜索的示例数据 return 是:

 {
            "_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"}
            },
        }
    }
}

这 return 如下:

"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.keywordmeasurements.part_type.keyword 字段。 raw 字段未指定,可能引用 2.x 中的旧默认值。

这是最可能的原因:5.0 mapping changes