title: connection error with tire/elasticsearch remote server
body: <p>I have installed a ubuntu 12.04 remote server with elasticsearch.</p>
  
  <p>I have installed elasticsearch with:</p>
  
  <pre><code>sudo apt-get update
  sudo apt-get install openjdk-7-jre-headless -y
  wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
  sudo dpkg -i elasticsearch-0.20.6.deb
  sudo service elasticsearch start
  </code></pre>
  
  <p>I get with <code>sudo elasticsearch status</code>:</p>
  
  <pre><code>* ElasticSearch Server is running with pid 2483
  </code></pre>
  
  <p>My elasticsearch remote server is working fine:</p>
  
  <pre><code>ubuntu12@juan:~/Escritorio/myapp$ curl http:/111.111.111.111:9200
  {
    "ok" : true,
    "status" : 200,
    "name" : "Hogan, Harold \"Happy\"",
    "version" : {
      "number" : "0.20.6",
      "snapshot_build" : false
    },
    "tagline" : "You Know, for Search"
  }
  </code></pre>
  
  <p>or with my subdomain:</p>
  
  <pre><code>ubuntu12@juan:~/Escritorio/myapp$ curl http://elasticsearchserver.mydomain.com:9200
  {
    "ok" : true,
    "status" : 200,
    "name" : "Hogan, Harold \"Happy\"",
    "version" : {
      "number" : "0.20.6",
      "snapshot_build" : false
    },
   "tagline" : "You Know, for Search"
  }
  </code></pre>
  
  <p>I can restart, start and stop elasticsearhc server.</p>
  
  <pre><code>sudo service elasticsearch restart
   * Stopping ElasticSearch Server                                                                                                                                                                      [ OK ] 
   * Starting ElasticSearch Server                                                                                                                                                                      [ OK ]
  </code></pre>
  
  <p>I have a <code>tire.rb</code> file in <code>config/initializer/</code> folder with the next code:</p>
  
  <pre><code>if Rails.env == 'production'
    Tire.configure do
      url "http://elasticsearchserver.mydomain.com:9200"
    end
  end
  </code></pre>
  
  <p>This is my capistrano task to reindex:</p>
  
  <pre><code>after "deploy:finalize_update", "deploy:elasticsearch:index_classes"
  namespace :deploy do
    namespace :elasticsearch do
     desc 'run elasticsearch indexing via tire'
      task :index_classes do
        run "cd #{deploy_to}/current &amp;&amp; bundle exec rake environment tire:import CLASS=Object FORCE=true "
      end
    end
   end
  </code></pre>
  
  <p>I'm using mongodb as database, so I have not make migrations before reindexing.</p>
  
  <p>This is capistrano error:</p>
  
  <pre><code>2013-04-06 14:25:50 executing `deploy:elasticsearch:index_classes'
   #
   #
   ** [out :: 111.111.111.111] Skipping index creation, cannot connect to Elasticsearch
   ** [out :: 111.111.111.111] 
   ** [out :: 111.111.111.111] (The original exception was: #&lt;Errno::ECONNREFUSED: Connection refused - connect(2)&gt;)
   ** [out :: 111.111.111.111] 
   ** [out :: 111.111.111.111] [IMPORT] Deleting index 'cvs'
   ** [out :: 111.111.111.111] 
   ** [out :: 111.111.111.111] rake aborted!
   ** [out :: 111.111.111.111] Connection refused - connect(2)
   ** [out :: 111.111.111.111]
   #
   #
  </code></pre>
  
  <p>I have uploaded to production server the tire.rb file and I have tried:</p>
  
  <pre><code>bundle exec rake environment tire:import CLASS=Object FORCE=true
  </code></pre>
  
  <p>and I get the same result:</p>
  
  <pre><code>Skipping index creation, cannot connect to Elasticsearch
  (The original exception was: #&lt;Errno::ECONNREFUSED: Connection refused - connect(2)&gt;)
  [IMPORT] Deleting index objects'
  rake aborted!
  Connection refused - connect(2)
  </code></pre>
  
  <p><strong>What am I doing wrong? How can I fix connection between tire/rails app and my elasticsearch server?</strong></p>