gpt4 book ai didi

node.js - 如何使用 mongoosastic 连接到 AWS Elasticsearch

转载 作者:太空宇宙 更新时间:2023-11-04 00:24:25 27 4
gpt4 key购买 nike

我正在尝试在我的 mongo db 数据库上创建搜索。我认为一个不错的选择是使用elasticsearch。所以我在 aws elastic search 上启动了一个集群。因为我有这个 Elasticsearch 用于开发目的,所以我设置了访问策略以开放对该域的访问。

this.es_connection = new elasticsearch.Client("elastic search end point as given on aws es domain page");

this.es_connection.ping(
{
requestTimeout: 30000,
hello: 'elasticsearch'
},
function(error) {
if (error) {
console.error('elasticsearch cluster is down!' + JSON.stringify(error));
} else {
logger.info('All is well in elasticsearch');
}
}
);

检查我正在尝试 ping npm 上的 usgin elascticsearch 包。我没有获得任何实时连接。 Node 服务器在本地主机上运行。当我从自己的浏览器查看端点 url 时,我收到成功消息。

如何将 aws es 服务与 mongoosastic 一起使用,我一直收到无实时连接错误。如果 AWS/ES 是一个 REST API,我如何将它与 mongoosastic 一起使用。

最佳答案

确保在连接期间指定您的 AWS 凭证。我建议使用这个库 https://www.npmjs.com/package/http-aws-es 。这对我有用:

var client = require('elasticsearch').Client({
hosts: 'Your host',
connectionClass: require('http-aws-es'),
amazonES: {
region: 'region',
accessKey: 'key',
secretKey: 'secretKey'
}
});

然后还要确保您进行了正确的查询,否则会导致 400 错误。

关于node.js - 如何使用 mongoosastic 连接到 AWS Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43339954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com