Elasticsearch-browser not connecting to remote server

Hello everyone,
I have a elasticsearch server running on google compute engine at port 9200 with no problems in firewalls.

When I run this curl command:

curl -u elastic:passwordChanged -H "User-Agent: Mozilla" -H "Origin: http://localhost:4200" -i public-ip:9200

HTTP/1.1 200 OK                                                                                                         
access-control-allow-origin: http://localhost:4200                                                                     
vary: origin                                                                                                            
access-control-allow-credentials: true                                                                                  
content-type: application/json; charset=UTF-8                                                                           
content-length: 541                                                                                                                                                                                                                             {                                                                                                                        
"name" : "elasticstash",                                                                                                
"cluster_name" : "elasticsearch",                                                                                       
"cluster_uuid" : "krcKlRl4SVmRI7nV1_NazA",                                                                              
"version" : {                                                                                                             
"number" : "7.13.2",                                                                                                   
"build_flavor" : "default",                                                                                             
"build_type" : "tar",                                                                                                   
"build_hash" : "4d960a0733be83dd2543ca018aa4ddc42e956800",                                                              "build_date" : "2021-06-10T21:01:55.251515791Z",                                                                        "build_snapshot" : false,                                                                                               
"lucene_version" : "8.8.2",                                                                                             "minimum_wire_compatibility_version" : "6.8.0",                                                                         "minimum_index_compatibility_version" : "6.0.0-beta1"                                                                 
"tagline" : "You Know, for Search"                                                                                    

As you can see I have enabled http.cors. and allowed all origin.

Now the problem I'm facing is I have an angular project which is trying to connect to this server but am getting

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9200/. (Reason: CORS request did not succeed).

I'm using elasticsearch-browser library to connect.

import * as es from "elasticsearch-browser";

export class AppComponent {
  private client: es.Client

  private connect(){
    this.client = new es.Client  ({
      node: 'http://external-ip:9200',
      httpAuth: 'elastic:changedPassword'


It works when the server is running on the same machine as angular, but is for some reason not changing the node ip.

What can I do to fix this?
I obviously changed the password for security reasons .

Never mind, it was a stupid issue. I followed some code on some website for setup probably for an older version of the elasticsearch library.
Now, I just replaced the node with host in this

 node: 'http://external-ip:9200',

and it is working now.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.