Skip to content

Custom analyzer not working as expected #697

@sonalkr132

Description

@sonalkr132

Steps to reproduce:

  • Set up 03-expert.rb template
$ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb
$ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb
$ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb
  • Add a custom analyzer to article title:
-    settings index: { number_of_shards: 1, number_of_replicas: 0 } do
+    settings index: { number_of_shards: 1, number_of_replicas: 0, analysis: {
+               analyzer: {
+                 rubygem: {
+                   type: 'pattern',
+                   pattern: "[\s#{Regexp.escape('.-_')}]+"
+                 }
+               }
+             } } do
       mapping do
         indexes :title, type: 'text' do
-          indexes :title,     analyzer: 'snowball'
+          indexes :title,     analyzer: 'rubygem'
           indexes :tokenized, analyzer: 'simple'
         end
  • Reimport records
$ rake environment elasticsearch:import:model CLASS='Article' FORCE=y
  • Start rails server and create a few articles with title as: example_1, example_gem
  • Search for example.

I don't get any results back. My pattern analyzer seems to be working fine:

$ curl -XGET 'localhost:9200/searchapp_application_development/_analyze?analyzer=rubygem&pretty=true' -d 'example_1'
{
  "tokens" : [
    {
      "token" : "example",
      "start_offset" : 0,
      "end_offset" : 7,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "1",
      "start_offset" : 8,
      "end_offset" : 9,
      "type" : "word",
      "position" : 1
    }
  ]
}

Any kind of help or general guidance about debugging this would be really appreciated :) I am using elasticsearch 5.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions