elasticsearch-model,Ruby On Rails,Ruby,elasticsearch Model" /> elasticsearch-model,Ruby On Rails,Ruby,elasticsearch Model" />

Ruby on rails 按elasticsearch模型搜索不返回记录

Ruby on rails 按elasticsearch模型搜索不返回记录,ruby-on-rails,ruby,elasticsearch-model,Ruby On Rails,Ruby,elasticsearch Model,我使用的是elasticsearch模型,我使用的是关注点方法,这是我的搜索方法。我用curl尝试了我的查询,它返回5个条目,但当我使用这个方法时 def search_index(*args) self.__elasticsearch__.search(*args) end 它给我上了一堂课 (byebug) Entry.search_index('test').records #<Elasticsearch::Model::Response::Records:0x007f

我使用的是elasticsearch模型,我使用的是关注点方法,这是我的搜索方法。我用curl尝试了我的查询,它返回5个条目,但当我使用这个方法时

def search_index(*args)
      self.__elasticsearch__.search(*args)
end
它给我上了一堂课

(byebug) Entry.search_index('test').records
#<Elasticsearch::Model::Response::Records:0x007f8eb85ca280 @klass=[PROXY] Entry(id: integer, created_at: datetime, updated_at: datetime, source_id: integer, data: text, uuid: string, source_entry_id: string, bytesize: integer), @response=#<Elasticsearch::Model::Response::Response:0x007f8eb85ca370 @klass=[PROXY] Entry(id: integer, created_at: datetime, updated_at: datetime, source_id: integer, data: text, uuid: string, source_entry_id: string, bytesize: integer), @search=#<Elasticsearch::Model::Searching::SearchRequest:0x007f8eb85ca438 @klass=[PROXY] Entry(id: integer, created_at: datetime, updated_at: datetime, source_id: integer, data: text, uuid: string, source_entry_id: string, bytesize: integer), @options={}, @definition={:index=>"self_driving_entries", :type=>"entry", :q=>"test"}>, @records=#<Elasticsearch::Model::Response::Records:0x007f8eb85ca280 ...>>, @options={}>
(byebug)条目。搜索索引(“测试”)。记录
#“测试”}>,@records=#>,@options={}>

如何通过此搜索方法访问我的记录?

您应该使用

回应

例如

Foo.new().search('1234').response.records

它将返回您的活动记录对象。

您是否尝试对结果调用
到a
?当您执行
输入时会发生什么情况。搜索索引(“测试”)。记录。到a
?该类中包含“PROXY”,这表明该类只是记录列表的代理。@Yoshiji先生,但我仍然不知道为什么需要将其转换为数组,记录是Elasticsearch::Model::Response::recordsUser.where(true)时,输出看起来像一个数组,但是如果执行
User.where(true).class
,您将看到它不是一个数组,而是一个来自代理类ActiveRecord::Relation的数组。在您的byebug中,我非常确定您可以执行
条目。搜索索引('test')).records.first
返回与条件匹配的第一个条目(如果有)
Foo.new().search('1234').response.records