0

I am very new to programming and I have been doing a lot of research for how to incorporate the Elasticsearch-rails gem into my apps. However, I have come to a point where I don't know how to get it up and running within my app. This is what I've done so far.

  1. put gem 'elasticsearch', '~> 1.0.5' in my gemfile.
  2. typed gem install elasticsearch in terminal

Now I see that I need to put the following code into my app files, but I'm not sure where it goes:

require 'elasticsearch'

And then what do I do with this code?:

client = Elasticsearch::Client.new log: true

client.transport.reload_connections!

client.cluster.health

client.search q: 'test'

# etc.

Also, I'm confused about the difference between the following gems:

gem 'elasticsearch', '~> 1.0.5
https://github.com/elasticsearch/elasticsearch-ruby

gem install elasticsearch-model elasticsearch-rails
https://github.com/elasticsearch/elasticsearch-rails
https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model

Are the elasticsearch-model and elasticsearch-rails already in elasticsearch-ruby?

In some tutorials I see it mentioned that you need to install elasticsearch on your computer and then navigate to http://localhost:9200 to see if it's up and running. Can't I just have it run within my app instead of having it run on my computer?

Thanks in advance for any insight you can provide me.

Valerie Mettler
  • 475
  • 4
  • 16
  • http://www.sitepoint.com/full-text-search-rails-elasticsearch/ I haven't followed it yet, but this tutorial looked a bit simpler than what you described above. And the `http://localhost:9200` seems to be a one-time test. Elasticsearch *will* run in your app. – dwilbank Oct 11 '14 at 08:47
  • @dwibank I tried following the tutorial you mentioned, and I ran into the same questions as above. I can never get http://localhost:9200 to run and I don't know why. Do I need to install JDK on my computer to do it? And in that case isn't that showing that elastic search also would need to run on your computer before it runs in your app? Thanks for your help! – Valerie Mettler Oct 11 '14 at 13:46
  • will try the tutorial and see what happens... – dwilbank Oct 11 '14 at 17:42
  • okay - first impressions - it must be installed on your local computer in order to do your development. It must be installed on heroku in order to make it work live in production. If you don't install it locally, you run into the error 'Could not find elasticsearch-api-1.0.5 in any of the sources'. And it looks like you do have to install java. Here is a thread describing how. http://stackoverflow.com/questions/22850247/installing-elasticsearch-on-osx-mavericks – dwilbank Oct 11 '14 at 17:59

1 Answers1

0

The code you are referring to is to connect and interact with your Elasticsearch server. Before you can do that you need to have Elasticsearch installed. You can think of Elasticsearch as its own webserver wrapped around a search engine that responds to a REST API.

Elasticsearch cannot run within your application. It needs to run on it's own. The easiest way to install Elasticsearch is to use Homebrew. With one command line you can install and have Elasticsearch running, it's really easy.

Once you have Elasticsearch running, you'll want to use the 'elasticsearch-model' gem, as that will be the interface between your application and Elasticsearch. The 'elasticsearch-rails' gem will handle rake tasks, and the 'elasticsearch-persistence' gem will handle ruby objects, which is not required if you are using Rails.

I hope this answered your questions. I just wrote an article on everything I covered in this answer at http://aaronvb.com/articles/intro-to-elasticsearch-ruby-on-rails-part-1.html