简体   繁体   中英

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. 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. For my database is firebase and use it service to create my elastic search instance. 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

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

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)

Then, you have to restart the ElasticSearch service after you make changes to the configuration.

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. Especially since you are passing the credentials in clear text..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM