3
votes

Not sure while working in local environment with elasticsearch i m getting this weird error, any help would me appreciated. thanks

Elasticsearch::Transport::Transport::Errors::NotFound ([404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"invoices","index":"invoices"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"invoices","index":"invoices"},"status":404})

2
Can you explain what you're doing exactly? The error simply says that the invoices index you're hitting does not exist in your local ES server.Val
@Val hi thanks for your reply, actually elastic search has been used in my existing project and its working fine everywhere but not in case of invoice model and i'm new for elastic search. i have updated the question with controller code, can you please have a look there.Anand
What this tells me is simply that you don't have any data in your local server. Did you forgot to create your index and load your data first maybe?Val
@Val i have 5 records in invoices tables. and not sure about index things.Anand
What do you mean by "table". Elasticsearch doesn't have any tables, but it has indexes. Do you have data in a database that is supposedly synched with your Elasticsearch server?Val

2 Answers

7
votes

Fixed issue by indexing ES by running these commands at rails console: -

Model.__elasticsearch__.create_index!
Model.__elasticsearch__.create_index! force: true
Model.import force: true 
0
votes

You can also follow this steps i find on rubydoc website :

require the task definition in your application, eg. in the lib/tasks/elasticsearch.rake file:

require 'elasticsearch/rails/tasks/import'

To import the records from your model, run:

bundle exec rake environment elasticsearch:import:model CLASS='ModelName'

Or you can use:

rake environment elasticsearch:import:all DIR=app/models

to import all models.