How to set a default analyzer to search for elasticity using a tire?

I have been experimenting with elasticsearch recently with ruby ​​on rails. I am having problems indexing my data, so I can search for items with multiple and non-multiple keywords.

The bus will allow me to assign an analyzer for each display attribute:

mapping do indexes title, analyzer: 'snowball' indexes body, analyzer: 'snowball' end 

Now let's say I have a keyword in the name 'tests'

if I do a search with an attribute in the request: http: // localhost: 9200 / myindex / mymapping / _search? q = title: test This will work.

However, if I do a general search without specifying an attribute like this:
http: // localhost: 9200 / myindex / mymapping / _search? q = test

He will not find the document.

How do I indicate that I want the analyzer to be "snowball" by default, so I don’t need to specify the attribute that I want to find?

ps I am using Tire Gem. Therefore, please respond as best as possible, given this.

+4
source share
2 answers

You can change the default analyzer using the 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 
+10
source

The easiest way to set this in the elasticsearch.yml settings file is:

 index.number_of_shards: 2 index.number_of_replicas: 0 index.analysis.analyzer.default.type: snowball 
+3
source

Source: https://habr.com/ru/post/1401012/


All Articles