Rails4, Elasticsearch alway return nil value

I setting Elasticsearch to rails project

Gemfile

gem 'elasticsearch-model'
gem 'elasticsearch-rails'

And Model file

require 'elasticsearch/model'
class HealthContent < ActiveRecord::Base

  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks



   ----SETTING_MODEL_CONFIGURATION---

end
HealthContent.import

And Test on Localhost console

Loading development environment (Rails 4.1.6)

2.1.2 :001 > HealthContent.search("test").records.count
HealthContent Load (0.6ms)  SELECT  `health_contents`.* FROM `health_contents`   ORDER BY `health_contents`.`id` ASC LIMIT 1000
HealthContent Load (0.3ms)  SELECT `health_contents`.* FROM `health_contents`  WHERE 1=0
=> 0 

2.1.2 :002 > HealthContent.search("test").records.count
HealthContent Load (0.3ms)  SELECT `health_contents`.* FROM `health_contents`  WHERE 1=0
 => 0 

Why this query always excute on SELECT "health_contents".* FROM "health_contents" WHERE 1=0

How to get correct results?


Source: ruby

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.