连接到 ElasticSearch 时,在 Node Js 应用程序上出现错误'Error: Unable to load PFX certificate'



在从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)

我的弹性客户是这样的。

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开头。

有一种方法可以解决这个问题

  1. Node.js版本14.x
  2. 添加此配置new elasticsearch.Client({ host: CONFIG.es_url, ssl:{ rejectUnauthorized: false } });

相关内容

最新更新