rs-pro / mongoid-elasticsearch

DEPRECATED - Consider using SearchKick https://github.com/ankane/searchkick
MIT License
61 stars 23 forks source link

Completion not working #18

Closed jengel3 closed 7 years ago

jengel3 commented 9 years ago

Hey guys, getting this error when trying to use the completion feature:

irb(main):026:0> Submission.es.completion('Te', 'name')
NoMethodError: undefined method `[]' for nil:NilClass
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mongoid-elasticsearch-0.8.3/lib/mongoid/elasticsearch/es.rb:101:in `completion'
        from (irb):26
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

I've used the same index setup as shown in the README:

  elasticsearch! index_mappings: {
    name: {
      type: 'multi_field',
      fields: {
        name: {type: 'string', boost: 10},
        suggest: {type: 'completion'}
      }
    },
    desc: {type: 'string'},
  }

Thanks in advance for any help.

rishijain commented 8 years ago

I think this should be Submission.es.completion('Te', 'name.suggest') as mentioned in the docs under "Completion".