node.js - 连接到 ElasticSearch 时在 Node Js 应用程序上出现错误“错误:无法加载 PFX 证书”
问题描述
从 NodeJs 应用程序查询弹性时,我收到以下错误堆栈跟踪。
Error: Unable to load PFX certificate
at configSecureContext (node:internal/tls:304:15)
at Object.createSecureContext (node:_tls_common:113:3)
at Object.connect (node:_tls_wrap:1619:48)
at HttpsAgent.createConnection (node:https:136:22)
at HttpsAgent.createSocket (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/_http_agent.js:265:26)
at HttpsAgent.createSocket (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/agent.js:77:11)
at HttpsAgent.addRequest (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/_http_agent.js:239:10)
at new ClientRequest (node:_http_client:305:16)
at Object.request (node:https:317:10)
at Object.request (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agent-base/patch-core.js:25:22)
我的 elastc 客户端看起来像这样。
import elasticsearch from 'elasticsearch';
import CONFIG from '../config/index';
const elasticClient = new elasticsearch.Client({
host: CONFIG.es_url,
});
export default {
search: async (...args) => {
try {
return await elasticClient.search(...args)
} catch (error) {
if (error.status == 400) {
return { hits: { total: 0 } }
}
throw error
}
}
}
弹性搜索的 URL 以 https 开头。
解决方案
有办法解决这个问题。</p>
- Node.js 版本 14.x
- 添加此配置
new elasticsearch.Client({ host: CONFIG.es_url, ssl:{ rejectUnauthorized: false } });
推荐阅读
- mysql - MySQL如何获取分钟级数据,数据频率为15秒
- php - 如何计算日历列上有多少事件?
- python - 如何比较 python 中的一些列表并将它们添加到数据框中?
- .net-core - 在应用程序之间切换时,即使访问令牌/ID 令牌有效,IdentityServer 4 也会导航到登录屏幕。有什么见解吗?
- c# - 将值从 datagridview 转换为文本框
- ruby-on-rails - 在 rails admin 中过滤虚拟字段
- java - 推特上传按钮的网址
- java - Spring Cloud Data Flow - 在 CommandLineRunner 之前处理异常
- python - XGBoost超参数ValueError的优化:标签必须由形式为0、1、2、...、[num_class - 1]的整数标签组成
- powershell - 将 $MyInvocation.UnBoundArguments 传递给 Powershell 中的嵌套函数