← Back to Upcase

Search partial words with elasticsearch (and tire gem)

(Patrik Bóna) #1

Hello All,

I would like to implement elasticsearch in one of my applications. I am using tire gem for this. But I have troubles to search just partial words. For example ‘oog’ should match ‘google’.

This is how I implemented it:

This is my model:

class Note < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  mapping do
    indexes :id, index: :not_analyzed
    indexes :title, boost: 5
    indexes :text

And this is how I search my notes:

Note.search load: true do
  query do
    string search_string, default_operator: 'AND'
  sort do
    by :_score, :desc

Everything works great except partial word matching.

I am fighting both, with elasticsearch api and tire gem DSL. I’ve tried to implement different analyser for words, but it did not help:

    indexes :title, :analyzer => "ngram", :search_analyzer => "search_ngram_analyzer", :index_analyzer => "index_ngram_analyzer", boost: 5, type: :string

Do you have any experiences with elasticsearch and tire gem? I would be glad for any hint. I already spent few hours in this without any success.

Many thanks in advance