我正在尝试对搜索结果进行排序,但我只是使用以下代码获得未排序的结果(在此示例中,我查询所有结果):
$query = new \Elastica\Query();
$query->setSort(array('id' => array('order' => 'desc')));
$resultSet = $type->search($query); // where $type is an elastica type object
$results = $resultSet->getResults();
作为参考,我将 FOSElasticaBundle 与 Symfony2 项目(使用$type = $this->container->get('fos_elastica.index.website.myType');
)一起使用,但这不应该有所作为。
如果我使用 直接在浏览器上进行查询http://localhost:9200/website/myType/_search?sort=id:desc&pretty=true
,我会得到正确排序的结果。