2012-03-12 93 views
4

我最近一直在用rails进行ruby的实验。我无法将我的数据编入索引,因此我可以使用复数和非复数关键字搜索项目。如何设置轮胎弹性搜索的默认分析仪?

轮胎让我来分配每个映射属性的分析:

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

它不会找到这个文件。

如何指定我希望默认分析仪为“雪球”,因此我不必指定要搜索的属性?

p.s.我正在使用轮胎宝石。所以请尽可能回答,因为您可以考虑这一点。

回答

10

有可能使用索引设置更改默认分析:

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 
3

这是最简单的设置这个在elasticsearch.yml设置文件:

index.number_of_shards: 2 
index.number_of_replicas: 0 
index.analysis.analyzer.default.type: snowball 
相关问题