Stephen Lead
Stephen Lead

Reputation: 1976

Searchkick with ElasticSearch returns "Faraday::ConnectionFailed: execution expired"

I've been using the searchkick gem with elasticsearch with no problems on a Rails 4.2.0 application. I have a single Video model using searchkick.

For some reason rake searchkick:reindex:all is now failing consistently with:

Reindexing Video... rake aborted! Faraday::ConnectionFailed: execution expired

I originally installed elasticsearch via brew install elasticsearch, which returns:

Warning: elasticsearch-1.3.4 already installed

Is it likely that my elasticsearch installation/database has become corrupted? If so, what is the best way to refresh it?

As per https://www.elastic.co/guide/en/elasticsearch/reference/1.4/indices-delete-index.html I tried curl -XDELETE 'http://localhost:9200/_all' but this doesn't resolve the error.

This problem occurs on my Mac, as well as Elastic Beanstalk when I deploy this code to AWS (both were previously working correctly).

Upvotes: 5

Views: 8333

Answers (3)

Navid Khan
Navid Khan

Reputation: 1169

For me, the problem was with the missing port in the URL. ( I am using AWS elasticsearch and not running it on localhost. )

I changed

ENV['ELASTICSEARCH_URL'] = Rails.application.credentials.dig(:elasticsearch, :url)

to

ENV['ELASTICSEARCH_URL'] = Rails.application.credentials.dig(:elasticsearch, :url) + ':443'

This does not affect all my projects, so I am guessing this has to do with a newer release.

Upvotes: 0

Pooja Mane
Pooja Mane

Reputation: 487

Add below lines of code in config/initializers/elasticsearch.rb

Searchkick.client = Elasticsearch::Client.new(hosts: ["localhost:9200"], retry_on_failure: true, transport_options: {request: {timeout: 250}})

You can specify this according to Rails environment.

Upvotes: 1

Stephen Lead
Stephen Lead

Reputation: 1976

Typically after hours of struggling I found the answer minutes after posting the question...

As per https://github.com/ankane/searchkick/issues/382 I added an initializer with:

Searchkick.client = Elasticsearch::Client.new(hosts: ["localhost:9200"], retry_on_failure: true, transport_options: {request: {timeout: 250}})

which seems to have solved the problem. I'll report back if it recurs.

Upvotes: 14

Related Questions