Skip to content

Commit

Permalink
Allow elastic _bulk API to accept any Content-Type, and split request…
Browse files Browse the repository at this point in the history
… body on newlines
  • Loading branch information
awesense-paul committed Dec 12, 2024
1 parent d7145ef commit 9ad456e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
12 changes: 1 addition & 11 deletions lib/handlers/elastic_bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions qryn_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down

0 comments on commit 9ad456e

Please sign in to comment.