我有一堆帶有位置字段的文檔,並且對於給定的搜索查詢與給定座標,我想根據它們的位置是否在給定座標的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