【问题标题】:Elasticsearch: aggregate nested objectsElasticsearch:聚合嵌套对象
【发布时间】:2016-03-30 15:07:24
【问题描述】:

我有以下结构中的数据

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

我想动态聚合嵌套对象的形式: [“对象类型”:此类型的记录数]。

例如对于 PERSON,我想得到类似的东西:

[地址:1000,信息:1230]

对于地址:

[街道:200,城市:100]

有可能吗?

【问题讨论】:

    标签: api search elasticsearch


    【解决方案1】:

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

    【讨论】:

    • 我必须在 PERSON 上使用什么过滤器才能获取地址和信息?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多