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 ElasticSearchExists (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 documentType = config.documentType // 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.exists(params).then(function (resp) { msg.exists = resp node.send(msg) }, function (err) { node.error(err) }) }) } RED.nodes.registerType('elasticsearch exists', ElasticSearchExists) }