# Connect Rails app to elasticsearch server

**URL:** <https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978>\
**Category:** Elasticsearch\
**Created:** [July 21, 2015, 11:27am UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978 "2015-07-21T11:27:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Ankit\_Agarwal](https://discuss.elastic.co/u/Ankit_Agarwal)\
**Post date:** [July 21, 2015, 11:27am UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/1 "2015-07-21T11:27:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jrgns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jrgns/32/640_2.png) [@jrgns](https://discuss.elastic.co/u/jrgns)\
**Post date:** [July 22, 2015, 2:29pm UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/2 "2015-07-22T14:29:38Z")

</div>

Hey

You can use the [Ruby client for Elasticsearch](https://github.com/elastic/elasticsearch-ruby). It's notRails specific, and allows you to query the Elasticsearch API. Also read through [the official writeup](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/_the_ruby_client.html).

---

<div class="post-metadata">

**Author:** ![Ankit\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Ankit\_Agarwal](https://discuss.elastic.co/u/Ankit_Agarwal)\
**Post date:** [July 30, 2015, 10:39am UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/3 "2015-07-30T10:39:08Z")

</div>

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!

Thanks.

---

<div class="post-metadata">

**Author:** ![jrgns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jrgns/32/640_2.png) [@jrgns](https://discuss.elastic.co/u/jrgns)\
**Post date:** [July 31, 2015, 6:20am UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/4 "2015-07-31T06:20:45Z")

</div>

You can also look at Chewy if paging is a concern: [https://github.com/toptal/chewy](https://github.com/toptal/chewy)

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

---

<div class="post-metadata">

**Author:** ![Ankit\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Ankit\_Agarwal](https://discuss.elastic.co/u/Ankit_Agarwal)\
**Post date:** [July 31, 2015, 7:37am UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/5 "2015-07-31T07:37:27Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![seanfcarroll](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@seanfcarroll](https://discuss.elastic.co/u/seanfcarroll)\
**Post date:** [February 7, 2017, 5:02pm UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/6 "2017-02-07T17:02:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ankit\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Ankit\_Agarwal](https://discuss.elastic.co/u/Ankit_Agarwal)\
**Post date:** [February 7, 2017, 5:22pm UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/7 "2017-02-07T17:22:56Z")

</div>

Hey

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:03pm UTC](https://discuss.elastic.co/t/connect-rails-app-to-elasticsearch-server/25978/8 "2017-07-05T22:03:29Z")

</div>


