2
我找不到使用op的任何字段的'ops',除了id。
型號:
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
控制器:
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"]}
有什麼不對?
**同**但是,工作:** OpsIndex :: Op.query匹配:{_id:「55263b48336f63004a000000 '}和 OpsIndex :: Op.filter(match_all:{}) **並且不工作:** OpsIndex :: Op.query(match:{name:'some text'})和OpsIndex :: Op.filter(範圍:{created_at:{gte:100}}) – user26171
是否分析了字段「名稱」?然後你的值爲'一些文本'的查詢將不起作用。請參閱http://stackoverflow.com/questions/18598418/elastic-search-exact-match – Zouzias
好的,我會檢查分析的選項名稱。但如何按範圍過濾? – user26171