我无法连接到谷歌云平台的弹性搜索

问题描述 投票:0回答:1

我在我的项目中使用angular 5,我已经在gcp中设置了elasticsearch和kibana。一切正常,直到我尝试将它连接到我的项目。我知道我必须发送我的凭据,但它没有用,我还尝试在elasticsearch.yml中添加一些CORS,但根本没有进展。对于我的数据库是firebase并使用它来创建我的弹性搜索实例。我想将它连接到我的项目,任何人都可以帮我这个吗?谢谢

这是我的代码:

var client = new elasticsearch.Client({

       host: 'http://user:[email protected]//elasticsearch',

      log: 'trace',
     });
     client.ping({
      // ping usually has a 3000ms timeout

    }, function (error) {
      if (error) {
        console.trace(error);
      } else {
        console.log('All is well');
      }
    });

这是服务器的响应

Failed to load http://35.225.247.57//elasticsearch/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 401.

我在elasticsearch.yml中添加了一些CORS

http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
angular firebase elasticsearch google-cloud-platform
1个回答
0
投票

确保http.cors.enabled设置也设置为true

配置http.cors.allow-origin有一个合理的值(*可以测试,但你不应该用它去生产;将它限制为你将使用的原点)

然后,您必须在更改配置后重新启动ElasticSearch服务。

sudo systemctl stop elasticsearch.service
sudo systemctl start elasticsearch.service

对于它的价值,您还应该禁用纯文本HTTP访问并专门切换到HTTPS。特别是因为您以明文形式传递凭证。

© www.soinside.com 2019 - 2024. All rights reserved.