【发布时间】:2013-12-24 13:10:23
【问题描述】:
我正在使用轮胎 gem 在我的数据库中查询弹性搜索。现在,我有一个模型ContentElastic,它连接到索引posts 和映射post。我将elasticsearch用作单个数据库,而不是作为另一个数据库的搜索引擎。所以,模型ContentElastic 是这样的:
class ContentElastic
include Tire::Model::Persistence
include Tire::Model::Search
include Tire::Model::Callbacks
index_name 'posts'
document_type 'post'
# fields
property :id
property :type, :type => "string"
property :username
property :name
property :datasource
property :content
property :language_id, :type => "long"
property :geotag
property :geo_enabled, :type => "boolean"
property :language_confidence, :type => "long"
property :tweet_id
...
end
现在,我写了一个这样的查询,从 elasticsearch 数据库中获取 10,000 条记录:
ContentElastic.search do
fields wanted_fields if wanted_fields.present?
query do
filtered do
query { string search_query } if search_query.present?
#### Filters
range_filters.to_a.each do |rf|
filter :range, rf if rf.present?
end
not_filters.to_a.each do |nf|
filter :not, nf if nf.present?
end
or_filters.to_a.each do |of|
filter :or, of if of.present?
end
and_filters.to_a.each do |af|
filter :and, af if af.present?
end
filter :script, {:script => script} if script.present?
terms_filters.to_a.each do |tf|
filter :terms, tf if tf.present?
end
end
end
size 10000
end
查询工作正常,我们正在获得结果。问题在于,对于 10,000 条记录,转换为 ruby 对象需要时间。有没有办法直接从轮胎声明中获取 elasticsearch 查询,并通过 RestClient 单独调用。
有没有办法在不执行轮胎查询的情况下获得弹性搜索查询。我在轮胎搜索块之后立即在轮胎中尝试了to_curl 方法,但似乎查询已经执行并且显示为Undefined method 'to_curl' for <#Tire::Collection>。
【问题讨论】:
标签: ruby-on-rails-3 tire