【发布时间】:2014-02-28 13:35:24
【问题描述】:
我有一堆带有位置字段的文档,对于具有给定坐标的给定搜索查询,我想根据它们的位置是否在给定坐标的 25 英里范围内对结果进行分组。但是,在每个组中,我希望结果不是按位置接近度排序的。有什么优雅的方法可以做到这一点?
例如,假设我有以下文件:
[
{ id: "1", price: 13.5, coords: $c1 },
{ id: "2", price: 10, coords: $c2 },
{ id: "3", price: 15, coords: $c3 },
{ id: "4", price: 5, coords: $c4 },
{ id: "5", price: 1, coords: $c5 },
]
其中 $c1、$c2、$c3 距离 $c 不到 25 英里,而 $c4、$c5 距离 $c 超过 25 英里。接近$c的顺序是$c3, $c2, $c1, $c5, $c4。在处理按价格从低到高排序的查询时,我想返回为
[
[
{ id: "2", price: 10, coords: $c2 },
{ id: "1", price: 13.5, coords: $c1 },
{ id: "3", price: 15, coords: $c3 },
],
[
{ id: "5", price: 1, coords: $c5 },
{ id: "4", price: 5, coords: $c4 },
]
]
【问题讨论】:
-
如果您发布一些示例文档以及您尝试完成此操作的任何查询,这可能会有所帮助。
-
@mconlin 示例已添加。谢谢!
标签: elasticsearch