Elasticsearch:聚合嵌套对象

时间:2016-03-30 15:07:24

标签: api search elasticsearch

我有以下结构中的数据

"mappings" : {
            "PERSON" : {
                "properties" : {
                    "ADDRESS" : {
                        "type": "nested",
                        "properties" : {
                        "STREET" : {
                            "type": "nested",
                            "properties" : {
                                "street": {
                                    "type": "string"
                                },
                                "number": {
                                "type": "integer"
                                }
                            }
                        },
                        "CITY" : {
                            "type": "nested",
                            "properties" : {
                                "name": {
                                    "type": "string"
                                },
                                "size": {
                                "type": "integer"
                                }
                            }
                        }
                        ,
                        "country": {
                            "type": "string"
                        }
                        }
                    },
                    "INFORMATION" : {
                        "type": "nested",
                        "properties" : {
                        "age": {
                            "type": "integer"
                        },
                        "sex": {
                            "type": "string"
                        }
                        }
                    }
                    "name" : {
                        "type": "string",
                    }
                }
            }
        }

我想在表单中动态聚合嵌套对象: ["对象类型":此类记录的数量]。

e.g。对于PERSON,我希望得到类似的东西:

[地址:1000,提供信息:1230]

和ADDRESS:

[STREET:200,CITY:100]

有可能吗?

1 个答案:

答案 0 :(得分:1)

您可以先根据PERSON或ADDRESS进行过滤,然后使用cardinality aggregation获取计数