我正在使用chewy。
除了id之外,我无法使用任何op字段来查找“ops”。
型号:
class Op
include Mongoid::Document
...
state_machine :initial => :draft do
...
end
update_index 'ops#op', :self
end
索引:
class OpsIndex < Chewy::Index
define_type Op
end
Controller :
def index
OpsIndex.reset! # => true
OpsIndex.purge # => {\"acknowledged\"=>true}
OpsIndex::Op.import # => true
scope = OpsIndex::Op.query term: { _id: '55263b48336f63004a000000' }
scope.total_count # => 1 nice!
scope.to_a.inspect => #<OpsIndex::Op:0x00000006f5f310 @attributes={\"_id\"=>{\"$oid\"=>\"55263b48336f63004a000000\"}, \"state\"=>\"deactivated\" ...
#But
scope = OpsIndex::Op.query term: { state: 'deactivated' }
scope.total_count # => 0
end
在development.log中:
[1m[32mOpsIndex::Op Search (7.4ms)[0m {:body=>{:query=>{:term=>{:_id=>"55263b48336f63004a000000"}}}, :index=>["development_ops"], :type=>["op"]}
[1m[32mOpsIndex::Op Search (3.2ms)[0m {:body=>{:query=>{:term=>{:state=>"deactivated"}}}, :index=>["development_ops"], :type=>["op"]}
怎么了?
最佳答案
大胆的猜测,但是下面的查询呢?
scope = OpsIndex::Op.query match: { state: 'deactivated' }
关于ruby-on-rails - 耐嚼只按ID搜索,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29728858/