[英]Sorting by number of nested elements with ElasticSearch and Tire
給定以下在稱為Post的模型上的映射,是否有可能構建一個查詢,以返回在特定時間范圍內(例如,過去7天)按投票數排序的帖子?
mapping do
indexes :id, type: 'integer'
indexes :user_id, type: 'integer'
indexes :name, boost: 10
indexes :body # analyzer: 'snowball'
indexes :created_at, type: 'date'
indexes :vote_count, type: 'integer'
indexes :topic_ids
indexes :topics do
indexes :id, type: 'integer'
indexes :name, type: 'string'
end
indexes :votes do
indexes :user_id, type: 'integer'
indexes :created_at, type: 'date'
end
end
我正在使用Tire in Rails 3.2.13。 我有一個郵政模型和一個投票模型。 帖子具有很多票,而投票屬於帖子。
是的,您可以按vote_count
數進行排序,也可以使用custom_score
查詢進行細粒度的相關性計算。
對於前者,類似:
require 'tire'
s = Tire.search do
query do
filtered do
query { all }
filter :range, 'created_at' => { from: '-7d' }
end
end
sort do
by :vote_count
end
end
puts s.to_curl
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.