Hi all:
I do have a file (my-file.json) that meets ES Bulk REST API. I can call it like this:
curl --data-binary "@./<my-file>json" -X POST <ES-cloud-URL>:443/_bulk?pretty \
-H "Authorization: <my-APi-key>" \
-H "Content-Type: application/json"
and the data gets loaded into my index. So I know the file is correct.
I would like not to use ES' API, and try to call the same REST end-point from NodeJS
const fs = require('fs/promises');
async function sendItToES()
{
const filePath = "<my-file>.json";
const stats = await fs.stat(filePath); //added this to be sure I was reading the right file
const fileSizeInBytes = stats.size;
const formData = new FormData();
formData.append('file', filePath);
const theURL = '<ES-cloud-URL>:443/_bulk?pretty -H';
const theLoad = await fetch (theURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-ndjson', //this one did not work either
'Authorization': '<my-APi-key>'
},
body: formData
})
.then(response => {
if (response.ok) {
console.log('the response:', response);
} else {
console.log('upload the error');
}
return response.json();
})
.then (data => {
console.log('server reponse', data);
})
.catch(err => {
console.error('error uploading file:', err);
});
}
I trie many different permutations and I always get "server reponse {error: {…}, status: 400}"
Thanks in advance.