我有这样的映射(以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"
}
}
}
}
}
}
答案 0 :(得分:0)
事实证明这是ES 1.7.4
的一个问题,我已升级到ES 2.1
并且我的查询确实返回了预期的响应!