Connect js client to elasticsearch behing nginx

Reverse proxy for elasticsearch and kibana

nginx setup

server {
  listen 8080;
  server_name XXXXXXXX;

   location / {
     return 301 /elasticsearch/;
   }

   location /elasticsearch/ {
     proxy_pass http://127.0.0.1:9500/;
     proxy_redirect http://localhost:9500 /elasticsearch/;
     auth_basic "Elasticsearch Authentication";
     auth_basic_user_file /etc/elasticsearch/user.pwd;
    }
  location /kibana/ {
      proxy_pass http://127.0.0.1:5601/;
      proxy_redirect http://127.0.0.1:5601/ /kibana/;
    }
}

Connect js client to elasticsearch behing nginx

var elasticsearch = require('elasticsearch');
 host =  {
    protocol: 'http',
    host: 'XXXXXXXX',
    port: 8080,
    path: '/elasticsearch/',
    auth: 'root:root'
  }


 var client = new elasticsearch.Client({
    host: host,  
 });


client.search({
  index : 'bank'
  // undocumented params are appended to the query string
  //hello: "elasticsearch"
}, function (error , response) {
  if (error) {
    console.error('elasticsearch cluster is down!' , error ,response);
  } else {
    console.log('All is well' , JSON.stringify(response));
  }
});

Comments

Popular posts from this blog

Proxy setting in java

Using logstash to import csv json files into elasticsearch

Kibana 4 Installation and Run as a service in ubuntu