嵌套聚合不在其存储桶中包含相关文档
Nested aggregation does not include relevant documents in it's bucket
我有这样的映射(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"
}
}
}
}
}
}
事实证明这是 ES 1.7.4
的问题,我已经升级到 ES 2.1
并且我的查询得到了 return 预期的响应!
我有这样的映射(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"
}
}
}
}
}
}
事实证明这是 ES 1.7.4
的问题,我已经升级到 ES 2.1
并且我的查询得到了 return 预期的响应!