代码之家  ›  专栏  ›  技术社区  ›  Steffen Brem

嵌套聚合在其存储桶中不包括相关文档

  •  0
  • Steffen Brem  · 技术社区  · 9 年前

    我有一个这样的映射(YAML格式):

    order:
        mappings:
            number: ~
            createdAt:
                type: date
            customer:
                include_in_parent: true # this is needed so we can use `customer.firstName:<term here>` on the order index
                type: nested
                properties:
                    id :
                        type : integer
                        index: not_analyzed
                    firstName:
                        type: string
                        index: not_analyzed
    

    然后我尝试搜索订单,并将相关客户作为一个集合。所以根据弹性搜索文档,我应该提出如下请求:

    http://shopblender.dev:9200/mango/order/_search

     {
        "size": 0,
        "aggs": {
            "customers": {
                "nested": {
                    "path": "customer"
                },
                "aggs": {
                    "customer_ids": {
                        "terms": {
                            "field": "customer.id"
                        }
                    }
                }
            }
        }
    }
    

    但当我执行此搜索时,它将有空的聚合(我有30个订单索引,它们都有一个内联客户对象):

    {
      "hits": {
        "total": 30,
        "max_score": 0,
        "hits": [
        ]
      },
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "timed_out": false,
      "aggregations": {
        "customers": {
          "doc_count": 30,
          "customer_ids": {
            "buckets": [
            ],
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0
          }
        }
      },
      "took": 1
    }
    

    为什么我不能使用 terms 嵌套属性上的聚合?我在这里错过了什么?

    更新

    这是 GET /mango/order/_mapping :

    {
        "mango": {
            "mappings": {
                "order": {
                    "_meta": {
                        "model": "Mango\\Component\\Core\\Model\\Order"
                    },
                    "properties": {
                        "createdAt": {
                            "type": "date",
                            "format": "dateOptionalTime"
                        },
                        "customer": {
                            "type": "nested",
                            "include_in_parent": true,
                            "properties": {
                                "email": {
                                    "type": "string",
                                    "index": "not_analyzed"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "id": {
                                    "type": "integer"
                                },
                                "lastName": {
                                    "type": "string"
                                }
                            }
                        },
                        "number": {
                            "type": "string"
                        },
                        "paymentState": {
                            "type": "string"
                        },
                        "shippingState": {
                            "type": "string"
                        },
                        "state": {
                            "type": "string"
                        }
                    }
                }
            }
        }
    }
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Steffen Brem    9 年前

    结果证明这是ES的问题 1.7.4 ,我已升级到ES 2.1 我的查询确实返回了预期的响应!