Skip to content

hasura/ndc-elasticsearch

Repository files navigation

Elasticsearch Connector

Docs ndc-hub License Status

With this connector, Hasura allows you to instantly create a real-time GraphQL API on top of your documents in Elasticsearch. This connector supports Elasticsearch functionalities listed in the table below, allowing for efficient and scalable data operations. Additionally, you will benefit from all the powerful features of Hasura’s Data Delivery Network (DDN) platform, including query pushdown capabilities that delegate all query operations to the Elasticsearch, thereby enhancing query optimization and performance.

This connector is built using the Go Data Connector SDK and implements the Data Connector Spec.

Features

Below, you'll find a matrix of all supported features for the Elasticsearch connector:

Feature Supported Notes
Native Queries + Logical Models
Simple Object Query
Filter / Search
Simple Aggregation
Sort
Paginate
Nested Objects
Nested Arrays
Nested Filtering
Nested Sorting
Nested Relationships

Before you get Started

  1. Create a Hasura Cloud account
  2. Install the CLI
  3. Create a project

Using the connector

To use the Elasticsearch connector, follow these steps in a Hasura project:

  1. Add the connector:

    ddn add connector-manifest es_connector --subgraph app --hub-connector hasura/elasticsearch --type cloud

    In the snippet above, we've used the subgraph app as it's available by default; however, you can change this value to match any subgraph which you've created in your project.

  2. Add your Elasticsearch credentials:

    Open your project in your text editor and open the base.env.yaml file in the root of your project. Then, add ES_CONNECTOR_URL, ES_CONNECTOR_USERNAME and ES_CONNECTOR_PASSWORD environment variables under the app subgraph:

    supergraph: {}
    subgraphs:
      app:
        ES_CONNECTOR_URL: "<YOUR_ELASTICSEARCH_URL>"
        ES_CONNECTOR_USERNAME: "<YOUR_ELASTICSEARCH_USERNAME>"
        ES_CONNECTOR_PASSWORD: "<YOUR_ELASTICSEARCH_PASSWORD>"

    Next, update your /app/es_connector/connector/es_connector.build.hml file to reference this new environment variable:

    # other configuration above
    ELASTICSEARCH_URL:
      valueFromEnv: ES_CONNECTOR_URL
    ELASTICSEARCH_USERNAME:
      valueFromEnv: ES_CONNECTOR_USERNAME
    ELASTICSEARCH_PASSWORD:
      valueFromEnv: ES_CONNECTOR_PASSWORD

    Notice, when we use an environment variable, we must change the key to valueFromEnv instead of value. This tells Hasura DDN to look for the value in the environment variable we've defined instead of using the value directly.

  3. Update the connector manifest and the connector link

    These two steps will (1) allow Hasura to introspect your data source and complete the configuration and (2) deploy the connector to Hasura DDN:

    ddn update connector-manifest es_connector
    ddn update connector-link es_connector
  4. Add Environment Variables

To configure the connector, the following environment variables need to be set:

Environment Variable Description Required Example Value
ELASTICSEARCH_URL The comma-separated list of Elasticsearch host addresses for connection Yes https://example.es.gcp.cloud.es.io:9200
ELASTICSEARCH_USERNAME The username for authenticating to the Elasticsearch cluster Yes admin
ELASTICSEARCH_PASSWORD The password for the Elasticsearch user account Yes default
ELASTICSEARCH_API_KEY The Elasticsearch API key for authenticating to the Elasticsearch cluster No ABCzYWk0NEI0aDRxxxxxxxxxx1k6LWVQa2gxMUpRTUstbjNwTFIzbGoyUQ==
ELASTICSEARCH_CA_CERT_PATH The path to the Certificate Authority (CA) certificate for verifying the Elasticsearch server's SSL certificate No /etc/connector/cacert.pem
ELASTICSEARCH_INDEX_PATTERN The pattern for matching Elasticsearch indices, potentially including wildcards, used by the connector No hasura*

Documentation

View the full documentation for the Elasticsearch connector here.

Contributing

Check out our contributing guide for more details.

License

The Elasticsearch connector is available under the Apache License 2.0.