How do I set the default analyzer for elastic search with tire?

前端 未结 2 2084
借酒劲吻你
借酒劲吻你 2021-01-06 04:38

I have been experimenting with elasticsearch lately with ruby on rails. I am having trouble getting my data indexed so I can search for items with both plural, and non-plur

相关标签:
2条回答
  • 2021-01-06 05:15

    It's easiest to set this in the elasticsearch.yml settings file:

    index.number_of_shards: 2
    index.number_of_replicas: 0
    index.analysis.analyzer.default.type: snowball
    
    0 讨论(0)
  • 2021-01-06 05:30

    It's possible to change default analyzer using index settings:

    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
    
    0 讨论(0)
提交回复
热议问题