UNPKG

prisme-flow

Version:

prisme platform flow engine

48 lines (42 loc) 1.26 kB
/** * Created by prisme.io on 09/06/2017. */ module.exports = function (RED) { var elasticsearch = require('elasticsearch') function ElasticSearchGet (config) { RED.nodes.createNode(this, config) this.server = RED.nodes.getNode(config.server) var node = this this.on('input', function (msg) { var client = new elasticsearch.Client({ host: this.server.host }) var documentId = config.documentId var documentIndex = config.documentIndex var documentIndex = config.documentIndex // check for overriding message properties if (msg.hasOwnProperty('documentId')) { documentId = msg.documentId } if (msg.hasOwnProperty('documentIndex')) { documentIndex = msg.documentIndex } if (msg.hasOwnProperty('documentType')) { documentType = msg.documentType } // construct the search params var params = { index: documentIndex, type: documentType, id: documentId } client.get(params).then(function (resp) { msg.payload = resp node.send(msg) }, function (err) { node.error(err) }) }) } RED.nodes.registerType('elasticsearch get', ElasticSearchGet) }