Skip to main content

Elasticsearch

This page describes how to connect to your Elasticsearch database and query it from your Appsmith app.

Connect Elasticsearch

caution

If you are a self-hosted user, you must whitelist the IP address of the Appsmith deployment 18.223.74.85 and 3.131.104.27 on your database instance or VPC before connecting to a database. For instructions on IP Filtering in Elasticsearch, see the Elasticsearch docs.

Connection parameters

The following is a reference guide that provides a description of the parameters for connecting to Elasticsearch.

Connect to Elasticsearch
Connect to Elasticsearch
Host URL
The network location where your Elasticsearch data is hosted. This can be a domain name or an IP address. To connect to a local database, see Connect Local Database for directions.

Port
The port number to connect to on the server.

Username/Password for Basic Auth
The account credentials used to log in to Elasticsearch.

Authorization Header
Instead of the username/password fields, you can provide an Authorization Header to authenticate your queries. This field is only used when the Username/Password for Basic Auth fields are empty.

Query Elasticsearch

The following section provides examples of creating basic CRUD queries to Elasticsearch.

info

For details on building more complex queries, see the Elasticsearch Document API documentation.

Method
The HTTP method to use for your query.

Options:
  • GET: Method used for requesting and fetching data.
  • POST: Method used for creating or updating records.
  • PUT: Method used for creating or updating records.
  • DELETE: Method used for deleting records.
Path
The endpoint to which your query is sent. This usually is made up of the index name and the name of an operation. For example: /users/_search is the endpoint used for searching the users index.

Body
The body content of your query.

Search documents

Queries run on top of indexed documents can be configured using the GET method.

Path:

/users/_search

Body:

{
"query": {
"match": {
"user.name": {{ UsersTable.searchText }}
}
}
}

The example above searches the users index for a name matching your user input from a Table widget called UsersTable.

Create a document

You can create a single new document using the POST method, with a JSON body that represents the document values; an id is automatically generated.

Path:

/users/_doc/

Body:

{
"name": {{ NewUserForm.data.Name }},
"email": {{ NewUserForm.data.Email }},
"gender": {{ NewUserForm.data.Gender }},
}

Above, user input is collected with a Form widget called NewUserForm.

Update a document

A single document can be updated using its id within an index using a POST request.

Path:

/users/_update/{{ UsersTable.selectedRow.id }}

Body:

// using a JSON Form widget to collect input
{
"doc": UpdateUserForm.formData
}

Above, the record with its id is selected from a Table widget called UsersTable and updated with input from a JSON Form widget.

This performs a partial update, where the properties you supply are added to the document; you don't need to add ones that have not changed.

Delete a document

A single document can be deleted using its id within an index using the DELETE method.

Path:

/users/_doc/{{ UsersTable.selectedRow.id }}

Above, the record with its id is selected from a Table widget called UsersTable.

See also

Data access and binding