是否可以限制嵌套字段的结果?
我有店主和商店,对于我的搜索结果,我想只获得2个商店而不是所有者的所有元素。
我的设置是foselasticabundle 5.0 + elasticsearch 5.4.3
我用以下查询尝试过:
$query = new Query();
$query->setParams(
[
'query' => [
'bool' => [
'must' => [
[
'match' => [
'_all' => $term,
],
],
[
'nested' => [
'path' => 'shops',
'score_mode' => 'max',
'inner_hits' => [
'size' => 2,
],
'query' => [
'match_all' => ['boost' => 1.0],
],
],
],
],
],
],
]
);
$found = $this->index->getType('owner')->search($query);
$query = new Query();
$query->setParams(
[
'query' => [
'bool' => [
'must' => [
[
'match' => [
'_all' => $term,
],
],
[
'nested' => [
'path' => 'shops',
'score_mode' => 'max',
'inner_hits' => [
'size' => 2,
],
'query' => [
'match_all' => ['boost' => 1.0],
],
],
],
],
],
],
]
);
$found = $this->index->getType('owner')->search($query);
查询有效,但忽略size参数
类型定义:
这是一个示例文档:
types:
owner:
properties:
name: { boost: 10, analyzer: snowball }
created: { type: date }
shops:
type: nested
properties:
name: ~
address:
type: nested
properties:
city: ~
street: ~
zip: ~
persistence:
driver: orm
model: AppBundle\Entity\Owner
provider: ~
finder: ~
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1.0,
"hits": [
{
"_index": "app_dev",
"_type": "owner",
"_id": "9",
"_score": 1.0,
"_source": {
"name": "Demo Name",
"created": "2017-06-30T22:46:47+02:00",
"shops": [
{
"name": "Shop 1 ",
"address": {
"city": "Test",
"street": "Teststreet 123",
"zip": "1234"
}
},
{
"name": "Shop 2",
"address": {
"city": "Test",
"street": "Teststreet 123",
"zip": "1234"
}
},
{
"name": "Shop 3",
"address": {
"city": "Test",
"street": "Teststreet 123",
"zip": "1234"
}
}
]
}
}
]
}
}