我希望你一切順利,我需要一些關于 Elasticsearch 引擎的幫助。我正在做的是我正在嘗試創建一個搜索引擎,我已成功通過 kibana 將我的資料發布到 elasticsearch 引擎。但是“但是我如何將 elasticsearch 的搜索組件添加到我的 react 應用程式中”,我在 kibana 索引中有大約 400 萬條記錄,當我嘗試直接從 react 搜索時,需要很長時間才能將記錄顯示到我的 frontapp 應用程式中節點 API。下面是 nodejs 的代碼,但這個代碼的問題只給了我 10 條記錄。
router.get('/tweets', (req, res)=>{
let query = {
index: 'tweets',
// size: 10000
}
if(req.query.tweets) query.q = `*${req.query.tweets}*`;
client.search(query)
.then(resp => {
return res.status(200).json({
tweets: resp.body.hits.hits
});
})
.catch(err=>{
console.log(err);
return res.status(500).json({
err
});
});
});
有什么方法可以將 elasticsearch 組件直接應用到我的 reactjs 應用程式中。就像 localhost:9200/index.. 直接來自 elasticsearch api?
uj5u.com熱心網友回復:
您可以使用SearchKit從您的 React 應用程式中直接查詢 elasticsearch。但請注意,將資料庫服務暴露在您自己的基礎設施之外是不好的做法。
uj5u.com熱心網友回復:
您對 Elasticsearch 的請求在我看來有點奇怪,您是否嘗試過使用檔案中的body類似內容進行搜索?這一行:
if(req.query.tweets) query.q = `*${req.query.tweets}*`;
似乎不是撰寫查詢的正確方法。您要搜索哪個欄位?
我看到您嘗試使用該size欄位,這應該是正確的。您還可以嘗試以下操作:
client.search({
index: 'tweets',
body: {
size: 1000, // You can put the size here to get more than 10 results
query: {
wildcard: { yourfield: `*${req.query.tweets}*` }
}
}
}, (err, result) => {
if (err) console.log(err)
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/348845.html
標籤:javascript 节点.js 反应 弹性搜索 基巴纳
上一篇:無法反序列化物件和物件串列
