Connect to Elastic Enterprise Search using Node.js

835 views Asked by At

I have following code to connect to Elastic Search Using Cloud ID

const { Client } = require('@elastic/elasticsearch')
//or using elastic.Client from ('elasticsearch')

var client = new Client({
    cloud: {
        id: 'cloudId'
    },
    auth: {
        username: "elastic",
        password: "eleastic_password",
    },

});

I can add and query data using above connection but I want the data to be queried from and added to Enterprise Search Cluster I have.. How can I make connection to Enterprise Search and not Kibana using nodejs? Apart from using http requests/axios, is there a way I can connect to Enterprise Search App cluster on Elastic Search using the Endpoint API Url?

1

There are 1 answers

2
AudioBubble On BEST ANSWER

So since I didn't get any answers. I finally found the way to connect to elastic enterprise search and that is by host url. Like this

var client = new elasticsearch.Client({
// do not forget to add the username and password in the url
  host:"https://<username>:<password>[complete_host_url]" 
}); 

One can also connect to multiple hosts at a time by providing the host value as array of host urls.