Last active
August 29, 2015 13:58
-
-
Save spalger/9938690 to your computer and use it in GitHub Desktop.
nodesToHostCallback for the elasticsearch.js client that filters out nodes which are not in "client" mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elasticsearch = require('elasticsearch'); | |
var baseNodesToHostCallback = require('elasticsearch/src/lib/nodes_to_host'); | |
var client = new elasticsearch.Client({ | |
/* host seed list */ | |
hosts: [ ... ], | |
// sniff every 5 minutes | |
sniffInterval: 1000 * 60 * 5, | |
// filter out non-client nodes, then pass | |
// to the default handler which parses and | |
// normalizes node list | |
nodesToHostCallback: function (nodes) { | |
return baseNodesToHostCallback(nodes.filter(function (node) { | |
var neverMaster = node.attributes && node.attributes.master === 'false'; | |
var isClientNode = neverMaster && node.attributes.data === 'false'; | |
return isClientNode; | |
})); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment