Please be sure of your agent type and version and pick the right documentation accordingly.
This is the documentation of the forest-express-sequelize and forest-express-mongoose Node.js agents that will soon reach end-of-support.
forest-express-sequelize v9 and forest-express-mongoose v9 are replaced by v1.
Please check your agent type and version and read on or switch to the right documentation.
This is still the latest Ruby on Rails documentation of the forest_liana agent, you’re at the right place, please read on.
This is the documentation of the django-forestadmin Django agent that will soon reach end-of-support.
If you’re using a Django agent, notice that django-forestadmin v1 is replaced by v1.
If you’re using a Flask agent, go to the v1 documentation.
Please check your agent type and version and read on or switch to the right documentation.
This is the documentation of the forestadmin/laravel-forestadmin Laravel agent that will soon reach end-of-support.
If you’re using a Laravel agent, notice that forestadmin/laravel-forestadmin v1 is replaced by v3.
If you’re using a Symfony agent, go to the v1 documentation.
Please check your agent type and version and read on or switch to the right documentation.
Interact with your Elasticsearch data
Creating the Smart Collection
Let's take a simple example from Kibana, we will use You can easily import the data using Kibana Home page section Ingest your data.
When it's done we can start looking at how to play with those data in Forest Admin.
First, we declare the bank-accounts collection in the forest/ directory. In this Smart Collection, all fields are related to document mapping attributes except the field id that is computed using the document _id.
You can check out the list of if you need them.
You MUST declare an id field when creating a Smart Collection. The value of this field for each record MUST be unique. On the following example, we simply use the UUID provided on every Elasticsearch documents.
You can add the option isSearchable: true to your collection to display the search bar. Note that you will have to implement the search yourself by including it into your own GET logic.
Implementing the routes
Before getting further, in order to search your data using filters, we need to define the Elasticsearch configuration.
Name
Type
Description
index
string
The name of your Elasticsearch index.
filterDefinition
string
Type of your Elasticsearch fields. Can be number, date, text,keyword
sort
array of objects
mappingFunction
function
(optional) Required only to modify the data retrieved from Elasticsearch. Example: (id, source) => { id, ...source}
Our custom filter translator only support number, keyword, text, date data types. Nonetheless, you can implement more filter mapper type in theutils/filter-translator.js
Implementing the GET (all records)
In the file routes/bank-accounts.js, we’ve created a new route to implement the API behind the Smart Collection.
The logic here is to list all the BankAccount records. We use a custom service service/elasticsearch-helper.js for this example. The implementation code of this service is available here.
To access the details view of a Smart Collection record, you have to catch the GET API call on a specific record. One more time, we use a custom service that encapsulates the Elasticsearch business logic for this example.
Now we are able to see all the bank accounts on Forest Admin, it’s time to implement the DELETE HTTP method in order to remove the documents on Elasticsearch when the authorized user needs it.
It's not an easy job to connect several data sources in the same structure. To accommodate you in this journey we already provide you a simple service that handles all the logic to connect with your Elasticsearch data.
(optional) Required only to sort your data. Example: [ { createdAt: { order: 'desc' } }]
Finally, the last step is to serialize the response data in the expected format which is simply a standard document. You are lucky forest-express-sequelize already does this for you using the RecordSerializer.