From 9ad456eb3f7650edb2728cb492fbe1674854f4fb Mon Sep 17 00:00:00 2001 From: Paul Reimer Date: Thu, 12 Dec 2024 15:03:06 -0800 Subject: [PATCH] Allow elastic _bulk API to accept any Content-Type, and split request body on newlines --- lib/handlers/elastic_bulk.js | 12 +----------- qryn_node.js | 2 -- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/handlers/elastic_bulk.js b/lib/handlers/elastic_bulk.js index 3d3bc8f8..7914694c 100644 --- a/lib/handlers/elastic_bulk.js +++ b/lib/handlers/elastic_bulk.js @@ -26,17 +26,7 @@ async function handler (req, res) { const docTarget = req.params.target || false - let streams - if ( - req.headers['content-type'] && - req.headers['content-type'].indexOf('application/x-ndjson') > -1 - ) { - // ndjson body - streams = req.body.split(/\n/) - } else { - // assume ndjson raw body - streams = req.body.split(/\n/) - } + const streams = req.body.split(/\n/) let lastTags = false const promises = [] if (streams) { diff --git a/qryn_node.js b/qryn_node.js index 01c8e71b..95405451 100755 --- a/qryn_node.js +++ b/qryn_node.js @@ -243,11 +243,9 @@ let fastify = require('fastify')({ }) const handlerElasticBulk = require('./lib/handlers/elastic_bulk.js').bind(this) writerMode && fastify.post('/_bulk', handlerElasticBulk, { - 'application/json': jsonParser, '*': rawStringParser }) writerMode && fastify.post('/:target/_bulk', handlerElasticBulk, { - 'application/json': jsonParser, '*': rawStringParser })