0

Currently I connect to a ElasticSearch cluster as follows:

(esr/connect "localhost:9200")

But I am concerned about availability so plan to run an ElasticSearch cluster.

How do I modify my Elastisch code to connect to a cluster (so that if a node is unavailable I can fall back to another node)? Does it do this by default? The ElasticSearch java rest client seems to offer this functionality so does Elastisch?

bm1729
  • 2,315
  • 3
  • 21
  • 30

2 Answers2

1

You can have setup of cluster with multiple hosts, this can can be configured using elasticsearch.yaml configuration file like:

.....
.....
discovery.zen.ping.unicast.hosts: ['192.168.10.1:9300', '192.168.10.2:9300']

also elect one node as master and other as slave or data node

# Allow this node to be eligible as a master node (enabled by default):
#
node.master: true
#
# Allow this node to store data (enabled by default):
#
node.data: true

also you can explore more about the same by below links about Zen discovery in clustered enviroment

Important configuration for elasticsearch

0

One of the benefits of using a service like elasticsearch is that it takes care of the availability part of the equation, in that ES itself will handle nodes going down. You do have to configure it intelligently, which is outside the scope of this question/answer.

The connect function here does not actually connect; it basically just creates a URI and options, and when you call a function like clojurewerkz.elastisch.rest.document/search, you give it the connection data, which is then used in an actual network operation.

So, you can call esr/connect as often as you like on as many URLs as you like, but you don't need to. I recommend reading elasticsearch's documentation to get familiar with the architecture, about nodes, clusters, indexes, shards, etc. -- and configure your elasticsearch cluster properly. But as far as the code itself goes, you are insulated from the architecture and need not worry about these details. This is true of elasticsearch's REST API, and thus the elastisch wrapper also provides this.

Josh
  • 4,726
  • 2
  • 20
  • 32
  • Thanks for the answer Josh. So will the connect function "discover" the other urls in the cluster? If not I don't see how this could work if the url I initially gave it was unavailable. I must be missing something obviously. – bm1729 Apr 13 '17 at 14:25
  • Incidentally, I found a library called spandex which allows you to specify a collection of urls when creating the client (as per the official elasticsearch rest client) so I feel this may fit my needs better. – bm1729 Apr 13 '17 at 14:25
  • spandex does node sniffing too, you can just pass one node when you connect and it will discover the others by itself and connect to them automatically. – mpenet Feb 21 '18 at 08:33