Skip to content

Instantly share code, notes, and snippets.

@spalger
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spalger/9938690 to your computer and use it in GitHub Desktop.
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.
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