我正在使用elasticsearch js库,以便将Hasura的事件POST请求通过管道发送到用于Elasticsearch的PUT请求中。通过Postman发送请求返回200 ok,但是通过Hasura发送相同的请求给我400错误,但没有响应。这是我的代码如下:
const elastic = require('../../util/elasticPipe')
const { sentryMessage } = require('../../util')
router.use('/pipe', async (req, res) => {
try {
const doc = await elastic.pipeDoc('user-activity-log', req.body.payload.event.data.new)
res.status(200).send(doc)
} catch (err) {
res.status(400).send(err)
sentryMessage(req, `Failed to index data to user-activity-log.`)
}
})
module.exports = router
const client = new Client({
node: 'http://localhost:9200',
auth: { username: 'username', password: 'password' },
})
const pipeDoc = async (index, data) => {
const res = await client.index({
index: index,
body: {
...data,
},
})
return res
}
module.exports = {
pipeDoc,
}