Supraja Suresh
Supraja Suresh

Reputation: 49

Elastic search query searches for 1=0 and returns no results

I have recently added ES to by Ruby on Rails application using elasticsearch-rails and elasticsearch-model gems. I have added proper index and mappings to my model and also imported it. But my search always returns 0 records. The query searches for 1=0 always.

Report.first.as_indexed_json returns this:

{"id"=>26, "user_id"=>7, "status"=>"current", "user"=>{"id"=>7,  "last_sign_in_at"=>Thu, 08 Sep 2016 04:39:46 UTC +00:00, "first_name"=>nil, "last_name"=>nil, "gender"=>nil, "year_of_birth"=>nil, "language"=>nil}} 

Where as:

> Report.search(26).records.count
  Report Load (0.4ms)  SELECT "reports".* FROM "reports" WHERE 1=0
 => 0 

> Report.all.search(query: { match: { id: 26 } }).records.count
  Report Load (0.4ms)  SELECT "report_s".* FROM "reports" WHERE 1=0
 => 0 

I expect 1 record to be returned here, but there are no matches.

Can anyone help me with this? Am I missing anything here?

The Report.import shows 4 records imported, but there is no change in the docs count in indices page.

Upvotes: 1

Views: 356

Answers (0)

Related Questions