【发布时间】:2013-08-28 19:29:57
【问题描述】:
我有一个可以归结为以下内容的映射(删除了不相关的字段):
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?它非常适合这样的事情。对于 elasticsearch,我会阅读他们的
sort文档:elasticsearch.org/guide/reference/api/search/sort -
排名是相对于当前结果计算的,还是整个数据集的总和?例如,在您的数据集中还有 10 票的“莎拉”,因此谁会使用不同的查询/过滤器排名 1?
-
正如@DamienRoche 所说,Redis 是处理这类事情的完美工具(假设票数和排名经常变化)。我不会为此想到 ElasticSearch。
标签: ruby-on-rails elasticsearch tire