Elasticsearch

This article describes how to create and maintain connections to your Elasticsearch cluster.

Before you can write your transformed data to an index in Elasticsearch, you should first establish a connection to your Elasticsearch cluster.

Create an Elasticsearch connection

Simple example

An Elasticsearch connection can be created as simply as follows:

CREATE ELASTICSEARCH CONNECTION my_elasticsearch
    CONNECTION_STRING = 'elasticsearch://search-elastic1-tiq6hb7ltwvcu2vwp3tbixyzey.us-east-1.es.amazonaws.com:443?cluster.name=elastic_main&ssl=true'
    USER_NAME = 'your_user'
    PASSWORD = 'your_password'
    COMMENT = 'My new Elasticsearch connection';

Note that an Elasticsearch connection must specify the cluster name it is connecting to within the connection string. This means that in order to connect to multiple clusters within your account, you need to create at least one connection per cluster.

Alter an Elasticsearch connection

Some connection options are considered mutable, meaning that in some cases, you can run a SQL command to alter an existing Elasticsearch connection rather than create a new one.

For example, take the Snowflake connection we created previously:

CREATE ELASTICSEARCH CONNECTION my_elasticsearch
    CONNECTION_STRING = 'elasticsearch://search-elastic1-tiq6hb7ltwvcu2vwp3tbixyzey.us-east-1.es.amazonaws.com:443?cluster.name=elastic_main&ssl=true'
    USER_NAME = 'your_user'
    PASSWORD = 'your_password'
    COMMENT = 'My new Elasticsearch connection';

To change the host you are connecting to but keep everything else the same without having to create an entirely new connection, you can run the following command:

ALTER ELASTICSEARCH CONNECTION my_elasticsearch
    SET CONNECTION_STRING = 
    'elasticsearch://your_new_host:443?cluster.name=elastic1&ssl=true'; 

Drop an Elasticsearch connection

If you no longer need a certain connection, you can easily drop it with the following SQL command:

DROP CONNECTION my_elasticsearch; 

However, note that if there are existing jobs that are dependent upon the connection in question, the connection cannot be deleted.


Learn More

To discover which connection options are mutable, and to learn more about the options, please see the SQL command reference for Elasticsearch.

Last updated