@elastic/elasticsearch npm library not working in mongodb realm function

jum4pzuy  于 2023-04-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(111)

我试图在mongodb领域函数中集成@elastic/elasticsearch npm库。为了实现这一点,我添加了@elastic/elasticsearch作为依赖项。

exports = async function(arg){
const { Client } = require('@elastic/elasticsearch');
  try {
    const apiKey = context.values.get("ES_API_KEY");
    const cloudId = context.values.get("ES_CLOUD_ID");
    const client = new Client({
    cloud: {
        id: cloudID
    },
    auth: {
        apiKey
    }
})
   return client;
   
  } catch(err) {
    console.log("Error occurred while executing:", err.message);
    return { error: err.message };
  }

当我这样做的时候,我得到了下面的错误。
failed to execute source for 'node_modules/@elastic/elasticsearch/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/UndiciConnection.js': FunctionError: failed to execute source for 'node_modules/undici/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/api-request.js': FunctionError: Cannot find module 'async_hooks'
是什么导致了这个问题?

fbcarpbf

fbcarpbf1#

目前MongoDB函数似乎不支持最新的@elastic/elasticsearch版本8。
将版本降级到7.17.0解决了此问题。

相关问题