Take the 2-minute tour ×

I have setup elastic search and tire for searching.

I have the following settings on my model:

  tire.settings :analysis => {
    :analyzer => {
      :spanish_snowball => {
        :type => "snowball",
        :language => "Spanish",
        :filter => %w{asciifolding lowercase}

And the following mappings:

 tire.mapping do
      indexes :id, :index => :not_analyzed
      indexes :name, :analyzer => 'spanish_snowball', :boost => 3
      indexes :urbanization, :analyzer => 'spanish_snowball'

      indexes :categories do
        indexes :name, :analyzer => 'spanish_snowball'

      indexes :tags do
        indexes :name, :analyzer => 'spanish_snowball'

I also defined the to_indexed_json method

def to_indexed_json
    to_json include: { categories: { only: [:name]}, tags: { only: [:name]} }

I want to ignore accents in my search, so I am using asciifolding in my spanish_snowball analyzer. However, the accents are not being ignored.

 => 10

=> 0

I have tested the analyzer with curl, the analyzer seems to be working fine

➜  ~  curl -XGET 'localhost:9200/businesses/_analyze?pretty=1&text=Japonés%20nobu&analyzer=spanish_snowball'
  "tokens" : [ {
    "token" : "japones",
    "start_offset" : 0,
    "end_offset" : 7,
    "type" : "<ALPHANUM>",
    "position" : 1
  }, {
    "token" : "nobu",
    "start_offset" : 8,
    "end_offset" : 12,
    "type" : "<ALPHANUM>",
    "position" : 2
  } ]
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

When you perform your search you need to tell elasticsearch how to analyze your search query.

The short form Model.search 'foo' doesn't (I think) allow you to specify those options but you can with the longer version:

Model.search do
  query do
    string 'foo', :analyzer => 'bar'
share|improve this answer
add comment

You need to specify the asciifolding filter on the query analyzer too. Like Frederick Cheung said, you need to create a new analyzer for the query or specify the one you have for indexing (I recommend the former since you generally don't want to break down your search query the same way you do your index records).

share|improve this answer
add comment

Your Answer


