我有歸結爲以下(去除不相關的領域)的映射:排行榜排名通過elasticsearch(含輪胎)
mapping
indexes :id, type: 'integer', index: :not_analyze
indexes :first_name, boost: 5, type: 'string', analyzer: 'snowball'
indexes :votes, type: 'integer', index: :not_analyzed
end
在我通過計算排名的Postgres的時刻,所以,鑑於以下項:
| first_name | votes |
----------------------
| Andy | 5 |
| Barry | 8 |
| Carl | 5 |
| Derek | 1 |
使用的是Postgres,我可以得到如下:
| first_name | votes | rank |
-----------------------------
| Barry | 8 | 1 |
| Andy | 5 | 2 |
| Carl | 5 | 2 |
| Derek | 1 | 4 |
是否有可能以某種方式通過elasticsearch計算這個排名?
你有沒有想過使用redis?這對於這樣的事情來說是完美的。對於彈性搜索,我會給他們的「排序」文檔進行閱讀:http://www.elasticsearch.org/guide/reference/api/search/sort/ –
排名是相對於當前結果計算的,還是總計整個數據集?例如,在你的數據集中還有'薩拉'有10票,誰將因此排名1與不同的查詢/過濾器? – Phil
正如@DamienRoche所說,Redis是這類東西的完美工具(假設票數和頻繁變化)。我不會想到ElasticSearch。 – Damien