简体   繁体   English

我无法连接到Google Cloud Platform中的弹性搜索

[英]i can't connect to my elastic search in google cloud platform

I am using angular 5 in my project and I have already setup my elasticsearch and kibana in gcp. 我在项目中使用angular 5,并且已经在gcp中设置了elasticsearch和kibana。 Everything works fine until I tried to connect it to my project. 一切正常,直到我尝试将其连接到我的项目。 I know I have to send my credentials, but it did not work and I tried also to add some CORS in the elasticsearch.yml, but no progress at all. 我知道我必须发送我的凭据,但是它没有用,我还尝试在elasticsearch.yml中添加一些CORS,但是完全没有进展。 For my database is firebase and use it service to create my elastic search instance. 因为我的数据库是firebase,并使用它服务来创建我的弹性搜索实例。 I want to connect it to my project can anyone help me with this? 我想将其连接到我的项目中,有人可以帮助我吗? thank you 谢谢

Here's my code : 这是我的代码:

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');
      }
    });

This is the response of the server 这是服务器的响应

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.

I added some CORS to elasticsearch.yml 我在elasticsearch.yml中添加了一些CORS

http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"

Make sure the http.cors.enabled setting is also set to true 确保将http.cors.enabled设置也设置为true

Configure the http.cors.allow-origin with a sensible value ( * is ok for testing but you should not go to production with that; limit it to the origin you will be using) 使用合理的值配置http.cors.allow-origin*可以进行测试,但是您不应该使用该值进行生产;将其限制为要使用的来源)

Then, you have to restart the ElasticSearch service after you make changes to the configuration. 然后,您必须在更改配置后重新启动ElasticSearch服务。

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

For what it's worth, you should also disable the plain-text HTTP access and switch over to HTTPS exclusively. 对于它的价值,您还应该禁用纯文本HTTP访问并仅切换到HTTPS。 Especially since you are passing the credentials in clear text.. 特别是因为您以明文形式传递凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Angular 2(quickstart应用)部署到Google Cloud平台 - Deploying Angular 2 (quickstart app) to Google Cloud platform 为什么我不能在 angular 上使用 action="example.php" 将我的表单连接到我的 php 文件 - Why can't I use action="example.php" on angular to connect my form to my php file Ionic Google Plus在浏览器平台上连接 - Ionic google plus connect on browser platform 角度通用项目中谷歌云平台的文件限制 - files limit in google cloud platform in angular universal project Angular2前端在Google云平台上的Spring Boot后端 - Angular2 frontend Spring Boot backend on Google cloud platform 使用 Python、Flask 和 Angular 的 Google Cloud Platform 上的 CORS 问题 - CORS issue on Google Cloud Platform using Python, Flask & Angular 如何在节点 js 中限制对谷歌云平台上存储桶文件的访问 - How to restrict access to a file for a bucket on google cloud platform in node js 如何在 Cloud9 上预览我的 Ionic 应用程序? - How can I preview my Ionic App on Cloud9? 在谷歌云中部署后,Angular 应用程序无法调用 Flask 服务器 API - Angular app can't call Flask server API after deploying in Google cloud 如何使我的 Firestore 搜索可重复? - How can I make my Firestore search repeatable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM