【问题标题】:Connect to Elasticsearch in a Fastify app with username and password via @fastify/elasticsearch package通过 @fastify/elasticsearch 包使用用户名和密码连接到 Fastify 应用程序中的 Elasticsearch
【发布时间】:2023-02-01 02:11:19
【问题描述】:

我是 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' });

【问题讨论】:

    标签: node.js elasticsearch fastify fastify-elasticsearch


    【解决方案1】:

    我终于找到了。只需遵循此模式<protocol>://<username>:<password>@<host>:<port>

    fastify.register(require('@fastify/elasticsearch'), { node: 'http://xxxx:xxxx@8.8.8.8:9200' });    
    

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 2021-07-01
      • 2020-01-27
      • 2021-07-24
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      相关资源
      最近更新 更多