![](/img/trans.png)
[英]Fastifyis not defined and fastify-postgres Fastify.pg.connect not working
[英]Connect to Elasticsearch in a Fastify app with username and password via @fastify/elasticsearch package
我是 Fastify 的新用戶。 我通過fastify-cli
創建了一個fastify@4.0.0
應用程序。 我想通過用戶名和密碼連接到 Elasticsearch,但在@fastify/elasticsearch
文檔中沒有提到它。 正如文檔所說:
const fastify = require('fastify')()
fastify.register(require('@fastify/elasticsearch'), { node: 'http://xxxx:9200' })
fastify.get('/user', async function (req, reply) {
const { body } = await this.elastic.search({
index: 'tweets',
body: {
query: { match: { text: req.query.q }}
}
})
return body.hits.hits
})
fastify.listen({ port: 3000 }, err => {
if (err) throw err
});
我不知道如何設置用戶名和密碼來連接到我的 Elasticsearch 實例。 是真的嗎?
fastify.register(require('@fastify/elasticsearch'), { node: 'http://8.8.8.8:9200', username: 'xxxx', password: 'xxxx' });
我終於找到了。 只需遵循此模式<protocol>://<username>:<password>@<host>:<port>
。
fastify.register(require('@fastify/elasticsearch'), { node: 'http://xxxx:xxxx@8.8.8.8:9200' });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.