angular - 我无法连接到Google Cloud Platform中的 Elasticsearch

标签 angular firebase elasticsearch google-cloud-platform

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

这是我的代码:

var client = new elasticsearch.Client({

       host: 'http://user:pass@35.225.247.57//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"

最佳答案

确保http.cors.enabled设置也设置为true
http.cors.allow-origin配置为一个合理的值(可以通过*进行测试,但您不应该使用该值进行生产;将其限制为要使用的来源)

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

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

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

关于angular - 我无法连接到Google Cloud Platform中的 Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49019433/

相关文章:

javascript - 为什么我的 ng-template 和 ngIf 中的代码无法正常工作

ios - 我正在尝试使用 Firebase 创建排行榜并显示用户名、高分、地区。

javascript - React fetch Firebase 获取唯一键值

javascript - 类型 'checked' .ts(2339) Angular 上不存在属性 'EventTarget'

Angular - FormArray 中的唯一性验证器

javascript - 如何使用 Angular 获取典型的 json 数据

Elasticsearch term查询没有给出任何结果

android - 将firebase数据库url(字符串)分配给数据库引用变量?

hadoop - Elasticsearch 中的分析

elasticsearch - 如何在 logstash.conf 文件中创建多个索引?