我正在尝试使用 ES javascript api 从 Elastic Search 获取数据并将其显示在我的 React Redux Redux-Saga 代码中。
function* getData() {
const response = async () => await client.msearch({
body: [
// match all query, on all indices and types
{},
{ query: { match_all: {} } },
// query_string query, on index/mytype
{ index: 'myindex', type: 'mytype' },
{ query: { query_string: { query: '"Test 1"' } } },
],
});
yield put(Success({
Data: response(),
}));
}
问题是我不知道如何让产量等待响应得到解决。
还有其他方法可以在 redux saga 和 es javascript-client 中使用 promise 吗?
最佳答案
我想到了。将答案放在这里供任何寻找它的人使用。
function* getData(data) {
const response = yield call(fetchSummary, data);
yield put(Success({
Data: response,
}));
}
async function fetchSummary(data) {
return await client.msearch({
body: [
// match all query, on all indices and types
{},
{ query: { match_all: {} } },
// query_string query, on index/mytype
{ index: 'myindex', type: 'mytype' },
{ query: { query_string: { query: data.query } } },
],
});
}
关于elasticsearch - 如何在 redux saga 中使用 async await?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51951839/