Connect Rails app to elasticsearch server

Hello everyone,

I am using logstash+elasticsearch to index server logs. The Elasticsearch server is running at localhost:9200 with millions of server log docs.
I also have a Rails app running at localhost:3000. I need to connect this rails app to the ES server.

I have read about the "elasticsearch-rails" gem but everywhere i found them using ActiveRecords/ Models. However, i don't think ActiveRecords are required for this. I just need a way to query the ES server index and fetch the documents inside my Rails app.

Is there a way to do this? Can anyone please help me with this situation? please comment if I am not clear with my question.

Thanks in advance.


You can use the Ruby client for Elasticsearch. It's notRails specific, and allows you to query the Elasticsearch API. Also read through the official writeup.

1 Like

Thanks. I actually implemented using Stretcher gem. But I just had a doubt. Can I actually use elasticsearch-rails gem with the scenario that I have? I was giving it a thought because the latter supports proper pagination and that can be helpful to view in my rails app. Please guide me if I am going in the wrong direction. My question might sound silly but I really want to learn this and I am very new to these stuff!


You can also look at Chewy if paging is a concern:

All of these libs will work, you will just have to do more / less work depending on their implementation.

Sure I will look into that.
Can the elasticsearch-rails gem be used in my case? Or the elasticsearch-rails gem needs to have some Model indexed? Because wherever I have read about the gem, i says you need to import data some ActiveRecord/Model and work on the indexed models. However, I do not have any ActiveRecord/Model to deal with. So can I use elasticsearch-rails gem?


@Ankit_Agarwal did you end up working with elasticsearch-rails? I have the same problem


No I did not use elasticsearch-rails. I used Stretcher gem for my implementation instead.