Hello,
I am working on a react app using elasticsearch , I have a problem for making post request with axios , the app is mainly based on react and Elasticsearch
.
This is the code working on node.js
const axios = require('axios');
const fs = require('fs');
const filePath = __dirname + '/products-bulk.json';
const indexName = 'indexrandom881';
const url = `http://localhost:9200/${indexName}/_bulk`;
fs.readFile(filePath, async (err, jsonData) => {
if (err) {
console.error({ err });
return;
}
const { data } = await axios.post(url, jsonData, {
headers: {
'Content-Type': 'application/x-ndjson'
}
});
console.info({ data });
});
I want to make it working on react or at least execute node.js code through react or html code
, this is my essay:
function App() {
const axios = require('axios');
const fs = require('fs');
const filePath = __dirname + '/national-es-bulk-index22.json';
const indexName = 'indexrandom881';
const url = `http://localhost:9200/${indexName}/_bulk`;
fs.readFile(filePath, async (err, jsonData) => {
if (err) {
console.error({ err });
return;
}
const { data } = await axios.post(url, jsonData, {
headers: {
'Content-Type': 'application/x-ndjson'
}
});
console.info({ data });
});
return (
<div className="App">
<h1>test</h1>
</div>
);
}
export default App;
Thanks in advance