1

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.

David
  • 208,112
  • 36
  • 198
  • 279
ankit.vic
  • 101
  • 3
  • 10

1 Answers1

-1

There are many solutions out there, but one that stands out is (e.g.) Stretcher which provides a very simple API that closely matches the Elasticsearch API.

For instance:

server = Stretcher::Server.new('http://localhost:9200')
res = server.index(:myindex).search(size: 10, query: {match_all: {}})

# res is of type Stretcher::SearchResults
res.total     # => 10
res.documents # => [#<Hashie::Mash _id="4" text="Hello 4">, ...]
...    
Val
  • 207,596
  • 13
  • 358
  • 360
  • Thank you for a quick response. I will look into it. – ankit.vic Jul 21 '15 at 14:07
  • Thanks again. 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 it supports proper pagination and that can be helpful to view in my rails app. Please guide me if I am going the wrong way. My question might sound silly but I really want to learn this and I am very new to these stuff! – ankit.vic Jul 30 '15 at 10:41