# Elasticsearch

## Setup

The following credentials keys are accepted:

* `host` (optional) -> The hostname / ip of the instance
* `port` (optional) -> The port of the instance. Default is `9200`
* `user` (optional) -> The username to access the instance
* `password` (optional) -> The password to access the instance
* `http_url` (optional) -> Comma-separated list of HTTP URLs to connect to the cluster
* `cloud_id` (optional) -> Elastic Cloud deployment ID
* `api_key` (optional) -> API key for authentication (when using Cloud ID)
* `service_token` (optional) -> Bearer token for authentication
* `tls` (optional) -> whether to use TLS for connecting (`true`/`false`)
* `cert_file` (optional) -> the client certificate for TLS (file path or raw)
* `cert_key_file` (optional) -> the client key for TLS (file path or raw)
* `cert_ca_file` (optional) -> the client CA certificate for TLS (file path or raw)

### Using `sling conns`

Here are examples of setting a connection named `ELASTICSEARCH`. We must provide the `type=elasticsearch` property:

{% code overflow="wrap" %}

```bash
$ sling conns set ELASTICSEARCH type=elasticsearch host=<host> user=<user> password=<password> port=9200
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export ELASTICSEARCH='elasticsearch://user:password@host.ip:9200'
export ELASTICSEARCH='{ type: elasticsearch, user: "user", password: "password", host: "host.ip", port: 9200 }'

export ELASTICSEARCH_CLOUD="{ type: elasticsearch, cloud_id: '<cloud_id>', api_key: '<api_key>' }"
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  ELASTICSEARCH:
    type: elasticsearch
    host: host.ip
    port: 9200
    user: <user>
    password: <password>
    tls: true # if TLS connection needed

  ELASTICSEARCH_URL:
    type: elasticsearch
    http_url: http://host1:9200,http://host2:9200

  ELASTICSEARCH_CLOUD:
    type: elasticsearch
    cloud_id: deployment:id
    api_key: your_api_key
```

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).
