我有一堆带有位置字段的文档,并且对于给定的搜索查询与给定坐标,我想根据它们的位置是否在给定坐标的25英里范围内进行分组。然而,在每个组中,我希望结果不是按位置靠近排序的。有没有优雅的方式来做到这一点?在elasticsearch中,如何通过位置邻近来对结果进行分组?
作为一个例子,假设我有以下文件:
[
{ 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英里之内,$ 4,$ C5均超过25英里远从$ c。靠近$ 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 },
]
]
,如果你发布一些例子doc和您曾经试图做到这一点任何疑问它可能会有所帮助。 – mconlin
已添加@mconlin示例。谢谢! – dementrock