python python - 1 year ago 76
Ruby Question

where to specify cluster details when using elastic search gem in Ruby

I want to access the data in

Elastic Search Cluster
from my
application. Lets say server is running at
and I want to access the end point

The following this documentation and came across this example:

require 'elasticsearch'

client = log: true

client.index index: 'my-index', type: 'my-document', id: 1, body: { title: 'Test' }

client.indices.refresh index: 'my-index' index: 'my-index', body: { query: { match: { title: 'test' } } }


  • where I will define the details of my
    elasticsearch cluster
    in the code? the cluster is running at

Answer Source

As the documentation specifics, the elasticsearch gem wraps elasticsearch-transport for connecting to a cluster and elasticsearch-api for accessing the elasticsearch API. From the documentation of elasticsearch-transport,

In the simplest form, connect to Elasticsearch running on http://localhost:9200 without any configuration:

So basically, client = log: true will by default connect to the cluster running at localhost:9200 (the same machine as your Rails app).

Go ahead and try executing after establishing the connection and you'll get to know if it succeeded or not.

Moreover, if your cluster runs on a different server, you can use the following to connect to it:

es = host: http(s)://<path-to-cluster-server>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download