我正在使用 ONGR ElasticsearchDSL Bundle 和 Symfony 3 来按纬度/经度坐标搜索城市列表,如下所示:
$repository = $this->elasticsearchManager->getRepository(CityDocument::class);
$search = $repository->createSearch();
$boolQuery = new BoolQuery();
$boolQuery->add(new MatchAllQuery());
$geoQuery = new GeoDistanceQuery('geo', '50km', $theSearch['location']);
$boolQuery->add($geoQuery, BoolQuery::FILTER);
$search->addQuery($boolQuery);
$documents = $repository->findDocuments($search);
虽然这给了我匹配城市的好结果,但我不清楚如何按与我的源点的距离(在 $theSearch['location'] 中找到)对它们进行排序,以便我让它们从最近到最远排序?!