4

我最近一直在用 ruby​​ on rails 试验 elasticsearch。我无法将我的数据编入索引,因此我可以搜索具有复数和非复数关键字的项目。

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

它不会找到该文档。

如何指定我希望默认分析器为“雪球”,这样我就不必指定要搜索的属性?

ps 我正在使用轮胎宝石。因此,请考虑到这一点,尽可能地回答。

4

2 回答 2

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
于 2012-03-12T16:23:58.737 回答
3

在 elasticsearch.yml 设置文件中进行设置是最简单的:

index.number_of_shards: 2
index.number_of_replicas: 0
index.analysis.analyzer.default.type: snowball
于 2013-07-25T19:51:00.910 回答