我在我的项目中使用FOSElasticaBundle和Symfony2,并且 MySQL 数据库上有条目和用户表,每个条目属于一个用户。
我想在数据库的所有条目中为每个用户获取一个条目。
参赛作品表示
[
{
"id": 1,
"name": "Hello world",
"user": {
"id": 17,
"username": "foo"
}
},
{
"id": 2,
"name": "Lorem ipsum",
"user": {
"id": 15,
"username": "bar"
}
},
{
"id": 3,
"name": "Dolar sit amet",
"user": {
"id": 17,
"username": "foo"
}
},
]
预期结果是:
[
{
"id": 1,
"name": "Hello world",
"user": {
"id": 17,
"username": "foo"
}
},
{
"id": 2,
"name": "Lorem ipsum",
"user": {
"id": 15,
"username": "bar"
}
}
]
但它返回表上的所有条目。我尝试将聚合添加到我的弹性搜索查询中,但没有任何改变。
$distinctAgg = new \Elastica\Aggregation\Terms("distinctAgg");
$distinctAgg->setField("user.id");
$distinctAgg->setSize(1);
$query->addAggregation($distinctAgg);
有没有办法通过术语过滤器或其他方法来做到这一点?任何帮助都会很棒。谢谢你。