On a Ubuntu server, I installed Meilisearch and it’s running as a service. Below is my configuration:
[Unit]
Description=Meilisearch
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/meilisearch --http-addr 127.0.0.1:7700 --master-key my_production_key
[Install]
WantedBy=multi-user.target
The meilisearch search service is successfully running. When I run from the terminal window curl -X GET http://127.0.0.1:7700/health -H "Authorization: Bearer my_production_key"
I get this output:
{"status":"available"}
Based on this, I believe that meilisearch is properly configured.
Then, I have a Ruby on Rails 8 application (through meilisearch-rails gem) and I am trying to connect to it. Here’s my meilisearch.rb
initializer:
MeiliSearch::Rails.configuration = {
meilisearch_url: 'http://127.0.0.1:7700',
meilisearch_api_key: 'my_production_key'
}
When I try to run a rake task to index database data, or simply do rails c
and then Model.reindex!
, I get this error:
An error occurred while trying to connect to the MeiliSearch instance: Failed to open TCP connection to 127.0.0.1:7700 (Connection refused - connect(2) for "127.0.0.1" port 7700) (MeiliSearch::CommunicationError)
/usr/local/bundle/ruby/3.2.0/gems/net-http-0.6.0/lib/net/http.rb:1665:in `initialize': Failed to open TCP connection to 127.0.0.1:7700 (Connection refused - connect(2) for "127.0.0.1" port 7700) (Errno::ECONNREFUSED)
For testing purposes, I tried to turn off the meilisearch service (systemctl stop meilisearch
) and then run again Model.reindex!
from the Rails application – and the error is still the same:
An error occurred while trying to connect to the MeiliSearch instance: Failed to open TCP connection to 127.0.0.1:7700 (Connection refused - connect(2) for "127.0.0.1" port 7700) (MeiliSearch::CommunicationError)
/usr/local/bundle/ruby/3.2.0/gems/net-http-0.6.0/lib/net/http.rb:1665:in `initialize': Failed to open TCP connection to 127.0.0.1:7700 (Connection refused - connect(2) for "127.0.0.1" port 7700) (Errno::ECONNREFUSED)
(in this case – the curl
command results in this error: curl: (7) Failed to connect to 127.0.0.1 port 7700 after 0 ms: Connection refused
– as expected)
For some reason, the Rails application cannot connect to the 127.0.0.1:7700
.
When I test this setup on my localhost (Mac OSX), the Rails application can successfully connect Meilisearch.
What might be the reason why the Ruby on Rails application cannot connect to 127.0.0.1:7700
?
1