我使用的輪胎索引和搜索汽車的數據庫:如果你搜索「紐約喬眼下彈性搜索多個字段
s = Tire.search Search.index_name do
query do |query|
query.text :_all, downcased_query, :type => :phrase
end
end
:
create :mappings => {
:cars => {
:properties => {
:id => {:type => 'string', :index => 'not_analyzed', :include_in_all => true},
:user_id => {:type => 'string', :index => 'not_analyzed'},
:name => {:type => 'string', :analyzer => 'snowball' },
:time => {:type => 'long', :index => 'not_analyzed'},
:origin_country => {:type => 'string', :analyzer => 'keyword', :include_in_all => false},
:origin_state => {:type => 'string', :analyzer => 'keyword', :include_in_all => false},
:origin_city => {:type => 'string', :analyzer => 'keyword', :include_in_all => false},
:dealer_name => {:type => 'string', :analyzer => 'snowball', :boost => 1.5, :include_in_all => false}
}
}
}
和查詢的樣子經銷商「,如果dealer_name是」Joe Dealer「,或者origin_state是」紐約「,但不是兩者,則它將匹配。有沒有辦法匹配origin_state是「紐約」,「dealer_name」是「Joe Dealer」(或者其中之一)?這個想法是我想要一個用戶輸入一個fre-form查詢字符串,並且能夠找到可能的最佳匹配,並且能夠找到他們希望進入紐約Joe Dealer的用戶,並找到在紐約Joe Dealer出售的所有汽車(或紐約的所有汽車或喬經銷商排名較低)。