Connect Rails app to Elasticsearch server

381 Views Asked by At

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.

1

There are 1 best solutions below

2
On

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">, ...]
...