Get response after recorded

Hi team.
i need to get response from elastic that data is written and then return success, but now endpoint returns success when data is sent for recording. how to do that?

 server.route({
  method: 'POST',
  path: '/api/newinv',
  async handler(req, h) {
	const payload = req.payload;

	await callWithRequest(req, 'bulk', {
		index: 'myindex',
		body: [
			{ "index" : { "_index" : "myindex", "_type" : "doc" }},
			payload,
		]
	})
	  .then(response => {
		console.log("WRITTEN");
		console.log({ error: null, id: response._id, result: response.result });
	  })
	  .catch(error => {
		console.log({ error: error });
	  });
	
	return "SUCCESS";
  },
});

I think you'd want to use the refresh parameter: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html#docs-refresh

So, probably you want either refresh=true or refresh=wait_for. Both have their drawbacks, and I'd say it really depends on how much writing you're doing as to whether or not you want to do this.