为什么我无法通过 Firebase Cloud 函数将文档插入到 Elasticsearch 索引中



我正在尝试通过Firebase Cloud Function将文档插入到我的Elasticsearch索引中,但不断收到以下错误:

{ Error: Request Timeout after 30000ms
    at 
/user_code/node_modules/elasticsearch/src/lib/transport.js:355:15
    at Timeout.<anonymous> 
(/user_code/node_modules/elasticsearch/src/lib/transport.js:384:7)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)
  status: undefined,
  displayName: 'RequestTimeout',
  message: 'Request Timeout after 30000ms',
  body: undefined }

但是当我运行在本地服务器实例上使用的相同代码片段时,插入文档没有问题。

const client = new elasticsearch.Client({
    hosts: ['http://******:**********@ipaddress:port']
});
client.index({
    index: 'csv',
    type: 'default',
    body: {
      message: 'hi'
    }
})
.then(res => console.log(res))
.catch(err => console.log(err));

云功能如下:

const client = new elasticsearch.Client({
    hosts: ['http://******:**********@ipaddress:port']
});
exports.createElasticEntry = functions.firestore
    .document('listings/{listingId}')
    .onCreate((snap, context) => {
        client.index({
            index: 'csv',
            type: 'default',
            body: {
              message: 'hi'
            }
        })
    .then(res => console.log(res))
    .catch(err => console.log(err));
});

在Cloud Functions中,使用免费的Spark计划,您无法与不受Google完全控制和管理的服务建立传出连接。 这是为了防止滥用。

如果要连接到外部服务,则需要升级到付费计划。

最新更新