如何设置轮胎弹性搜索的默认分析器?

dem*_*sus 4 ruby-on-rails elasticsearch tire

我最近一直在尝试使用ruby on rails.我无法将数据编入索引,因此我可以搜索包含复数和非复数关键字的项目.

轮胎将允许我为每个映射属性分配一个分析器:

mapping do
  indexes title, analyzer: 'snowball'
  indexes body, analyzer: 'snowball'
end
Run Code Online (Sandbox Code Playgroud)

现在,假设我在"测试"标题中有一个关键字

如果我使用查询中的属性进行搜索: http:// localhost:9200/myindex/mymapping/_search?q = title:test 它将起作用.

但是,如果我进行常规搜索而不指定如下属性:
http:// localhost:9200/myindex/mymapping/_search?q = test

它找不到该文件.

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

ps我正在使用轮胎宝石.所以请尽可能地回答这个问题.

imo*_*tov 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
Run Code Online (Sandbox Code Playgroud)