Bulk NodeJS fetch

Thanks Ashish, it finally got it to work. bellow if the code just incase somebody else run into the same issue

const fs = require('fs/promises'); // for file manipulation, notice we are not using fs but fs/promises

async function sendItToES()
{
    const theURL = 'https://<for ES cluster>:443/_bulk?pretty';
   
    const theLoad = await fetch (theURL, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-ndjson',
            'Authorization': 'ApiKey <your API key>'
        },
        body: await fs.readFile('<your file and path>')
    })
    .then(response => {
        if (response.ok) {
            console.log('succeded sending payload to ES');
        } else {
            console.log('upload to ES failed: ', response);
        }
        return response.json();
    })
    .then (data => {
        console.log('data sent to ES: ', data);
    })
    .catch(err => {
        console.error('error uploading file: ', err);
    });
}
1 Like