Configuring DB connectors - Elastic Search

Studio enables you to use the database connectors to connect to your databases like Elasticsearch, MongoDB, CouchDB, DynamoDB, and so on.

Elasticsearch is a distributed, open-source search and analytics engine. You can store, search, and analyze huge volumes of data quickly. You can query Elasticsearch and in near real-time get back responses in a matter of a few milliseconds.

Configuring Elasticsearch connector

To add a DB connector, under Studio > Connectors, click (+) Connector.

You need to first configure the database. Enter the Connector name which would be used when you need the connector in your apps and while adding queries.

The most important part of the process is to provide the Connection strings. You can add the connection details or then provide the Connection string fields required for establishing a database connection.

For the Elasticsearch connector you need to provide the following:

  • Host: Enter the correct Hostname
  • Port: Enter the Port name
  • Username and Password: The Integration with Elasticsearch is supported using the username and password for authentication.
  • WhiteList IP: You can enable WhitelistIP to specify that DronaHQ be permitted to connect to the Elasticsearch database by whitelisting the specified IP address.

Once these configurations are added, click Test Connection. If the authentication is successful you would get the response accordingly. Click Save to Finish configuration.

Adding queries to the Elasticsearch connector

Now that you have configured the connector you will find it under the Connectors list. Now to fetch data or undertake any other action, click the Add query option available once your connection is ready.

Here you will have a list of Actions that you can carry out like query, update, delete, and so on.

You can provide a name to the query using Enter a Service name. Add your query and click Run or press Ctrl + enter to run the query. The rows returned from the document are shown in the Response section.

You can also add dynamic values using the Variables. To add the variable, click Variables > +Add. Add the FieldName and select the Field type. Add a Test Value to check the results before saving. You can also add a Default value or make it Mandatory. Add the Help text that would be shown with the field. Once you have entered the details, click Add Variable. The variable would be listed under Variables. You can make use of the variable in the query where you created the variable.

To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered for fetching data. When using the connector queries the dynamic variables would have to be linked to the respective control for further run-time functioning.

Using Elasticsearch connector

Search record

Now let us take a simple example to scan an Elasticsearch document and get all records with the first name as “p”. You can display the data in a tablegrid control. In this case, you simply need to select the action as search as per the Elasticsearch syntax and add the variable that would be provided at runtime. A sample is shown in the illustration below.

Add the query as seen above and run to verify the output. Once done Save the query.

Now under Bind Data, you can use this query to get data. Add a tablegrid control and configure the Connector. Go to Bind Data> Connectors and configure the query.

In the example, we would be providing the textinput2 as a dynamic value using the Keywords.

So now when you take a preview of the respective form you would be able to see the data accordingly.

Get all data

In this case, you simply need to select the type of action as Search as per the Elasticsearch syntax. You want to get all the data, so we do not provide any conditions.

You can then configure the query to display data in a control like the tablegrid control or a text label, and so on. Go to Bind Data> Connectors and configure the query.

Now when you run the query you would get the data from the document.

Insert data

Using the DB Connector for Elasticsearch is similar to using it with other documents and collections like CouchDB, DynamoDB and so on. You can make use of the Queries to fetch data as well bind data such that you can undertake the insert, update, delete actions as well.

Now if you want to insert data to your document you can use the Create action for the same with the respective values for the same. You can fetch it from your form and assign the respective values using the dynamic variables.

In this example, you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords.

So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to add data to your Elasticsearch document.

|297x269.2557289500755

Update Data

You can also update data from the table using the Update action. You simply need to define the variables to get data dynamically from the respective controls. In this example, we would select the record and get the Id of that record from the tablegrid. Then using the input parameter we will update the First name. So the update query would be defined as seen below.

In this example, you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords.

So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to update the selected record to your Elasticsearch document.

Similarly to delete data from your document you would have to choose Action as deleteItem and provide the key to delete the item using the dynamic variable. It could be any scenario like choosing a record from your table grid control and fetching the ID and adding the action flow to delete the record.