我最近一直在尝试用Elasticsearch在Rails上使用ruby。我在为数据编制索引时遇到麻烦,因此我可以搜索带有复数和非复数关键字的项目。
Tire将允许我为每个映射属性分配一个分析器:
mapping do indexes title, analyzer: 'snowball' indexes body, analyzer: 'snowball' end
现在,假设我在“测试”标题中有一个关键字
如果我使用查询中的属性进行搜索: http:// localhost:9200 / myindex / mymapping / _search?q = title:test 它将起作用。
但是,如果我在不指定属性的情况下进行常规搜索,例如: http:// localhost:9200 / myindex / mymapping / _search?q = test
它将找不到该文档。
如何指定我希望默认分析器为“ snowball”,而不必指定要搜索的属性?
ps我正在使用Tyre Gem。因此,请考虑到这一点,尽力回答。
可以使用索引设置更改默认分析器:
require 'rubygems' require 'tire' Tire.index 'articles' do delete create :settings => { :index => { :analysis => { :analyzer => { :default => { :type => 'snowball' } } } } }, :mappings => { :article => { :properties => { :title => { :type => 'string', :analyzer => 'snowball'}, :body => { :type => 'string', :analyzer => 'snowball'} } } } store :title => 'Tests', :body => "Plural" store :title => 'Test', :body => "Singular" refresh end