Hi, i am using searchkick in my rails app. i am facing with a wierd error where when i am searching through my application, it is showing me the following error. However, if i use rails console and call the same function in the console i am getting the response. I am not sure if this is an issue for searchkick talking to elasticsearch.
The exception is :
Elasticsearch::Transport::Transport::Errors::BadRequest in JobsController#jobs
See if Job.reindex fixes it.
I see this error when my order or where clauses contain attributes that are not actually present in the model.... or if I hadn't reindexed after adding any such attribute to the model.
Yes, this is expected in those cases. I'll make the error message friendlier when I have a chance.
It did not work. Interesting thing is it works on the rails console ... but not on the rails app.
@peddinti Are you running the application, and the console both in development environment?
If it works in the console but not the web server, chances are the environments are different. Try:
p ENV["RACK_ENV"]
p ENV["RAILS_ENV"]
p Job.searchkick_index.name
for each.
Thanks it turns out when i did reindex using rake, it reindexed in the dev environment and when i did rails console, it opened in dev environment and hence it was working there and not in production. reindex in production solved it. Thanks
@peddinti : i am getting an error similar to yours
Searchkick::InvalidQueryError ([400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {events_production_20150303045215588][0]: RemoteTransportException[[Ka-Zar][inet[/172.31.21.79:9300]][indices:data/read/search[phase/query+fetch]]]; nested: SearchParseException[[events_production_20150303045215588][0]: query[ConstantScore(*:*)],from[0],size[40]: Parse Failure [Failed to parse source [{\"query\":{\"match_all\":{}},\"size\":40,\"from\":0,\"sort\":{\"name\":\"asc\"},\"facets\":{\"category\":{\"terms\":{\"field\":\"category\",\"size\":100000}}},\"fields\":[]}]]]; nested: SearchParseException[[events_production_20150303045215588][0]: query[ConstantScore(*:*)],from[0],size[40]: Parse Failure [No mapping found for [name] in order to sort on]]; }]","status":400}):
Can you please state which commands you used to resolve the issue
@For me the problem was no record in one table included in searchkick. Make sure you have at least one record in each table, then rake searchkick:reindex.all and try again.
Most helpful comment
@For me the problem was no record in one table included in searchkick. Make sure you have at least one record in each table, then rake searchkick:reindex.all and try again.