Elasticsearch Dao

In the JBStrap framework, the lowest level of ElasticSearch data handling is using the ElasticSearchDao API. This API implements all supported tasks available for the application. The task handled by the API is compatible with the Record and Criteria classes.

Administrative tasks

In this section, we introduce methods intended to fulfil administrative tasks on an ElasticSearch server. These methods provide information about the status of the server and the individual indexes.

Getting metadata

Use this method to get metadata. Metadata provide information on index names, server and cluster status and configuration. The query returns a org.elasticsearch.cluster.metadata.MetaData class. Read more about this class in the ElasticSearch documentation . Use the following method to get metadata:

Getting the cluster status

Use this method to get the status of an ElasticSearch cluster. The method returns the org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse class. Read more about this class in the ElasticSearch documentation . Use the following method to get the cluster health:

Getting the index status

Use this method to get the status of an ElasticSearch index. The method returns the org.elasticsearch.cluster.health.ClusterIndexHealth class that contains information about the index status. Read more about this class in the ElasticSearch documentation . Use the following method to get the index status and specify the entity associated with the index:

Getting the index statistics

Use this method to get the index statistics. The method returns a org.elasticsearch.action.admin.indices.stats.IndexStats object. Read more about this object in the ElasticSearch documentation . To get the index statistics, use the below method. In a parameter, specify the data class corresponding to the index:

Checking if an index exists

Use the below method to check if an index exists in the database. The method returns a boolean value (true if the index exists and false if not).

Rebuilding an index

You may need to rebuild an index in the ElasticSearch database. When rebuilding an index, the data contents are restructured, but are not modified. Use the following method to rebuild an index:

Handling indexes in an ElasticSearch database

In this section, we introduce the methods used to create indexes or removing indexes from an ElasticSearch database.

Creating an index

JBStrap's ElasticSearch plugin offers you two options to create an index. The first is to create an index based on the associated data class or based on an ElasticSearch DataDescriptor. In both cases the index is created using the data class annotations .

Creating an index based on a data class:

Creating an index based on an ElasticSearch DataDescriptor:

Deleting an index

There are two ways to delete an index from an ElasticSearch database. The first one is to delete it based on the associated data class or to use an ElasticSearch DataDescriptor. In both cases the index itself and all related data are deleted permanently.

Deleting an index based on the associated data class:

Deleting an index based on an ElasticSearch DataDescriptor:

Data handling in ElasticSearch indexes

Fetch

Use this functionality to programmatically retrieve data. You can use this functionality to retrieve data from an ElasticSearch database index based on the data class or DataDescriptor associated with the index. Apply filter criteria to the query. Filter criteria are JBStrap Criteria objects. Query results are returned as DataRecord or List<DataRecord> objects. You can initiate a query of all the corresponding records or you can retrieve a subset of the record for faster response time.

If you initiate the query based on a DataDescriptor and you also specify the client object, then the access rights in the DataDescriptor are checked. If a user does not have read rights for the data (as specified in the DataDescriptor), the query returns an error, preventing unauthorized access to the data.

Initiating a generic query by using the index's data class:

Fetching every data through an entity:
Fetching every data through an entity, while checking for access rights:
Fetching the records, that meet the specified filters, through an entity (fetching every valid Record):
Fetching every Record, that meets the specified filters, through an entity while checking for access rights:
Fetching the first 50 records through an entity that meets the specified filters (Every record that has the column1 value of 100. If there are more than 50, only the first 50 will be fetched):
Getting the next 50 records (51-100), while checking for access rights:
Getting the first 50 records that meet the specified criteria, and ordering it descending order by column2:
Fetching the same record, while checking for access rights, and ordering it, descending by column2 and ascending by column3:

Initiating a generic query using the ElasticSearch DataDescriptor:

Fetching every data through a DataDescriptor:
Fetching every data through a DataDescriptor, while checking for access rights:
Fetching every data that meets the specified Criteria, through a DataDescriptor(fetching every valid Record):
Fetching every valid record, while checking for access rights, through a DataDescriptor:
Fetching the first 50 records through a DataDescriptor that meets the specified filters (Every record that has the column1 value of 100. If there are more than 50, only the first 50 will be fetched):
Getting the next 50 records (51-100), while checking for access rights:
Getting the first 50 records that meet the specified criteria, and ordering it descending order by column2:
Fetching the same record, while checking for access rights, and ordering it, descending by column2 and ascending by column3:

Getting a record from the index using its unique ID:

Fetching the record that corresponds to ID 23, from an entity:
Fetching the record that corresponds to ID 23, from an entity, while checking for access rights:
Fetching the record that corresponds to ID 23, from a DataDescriptor:
Fetching the record that corresponds to ID 23, from a DataDescriptor, while checking for access rights:

Counting the records:

Counting the record rows in an entity:
Counting the record rows in an entity, while checking for access rights:
Counting the record rows in an entity that meet the specified criteria (has the column1 value of 100):
Counting the record rows in an entity that meet the specified criteria while checking for access rights:
Counting the records in a DataDescriptor:
Counting the rows in a DataDescriptor, while checking for access rights:
Counting the rows in a DataDescriptor that meet the specified criteria (has the column1 value of 100):
Counting the rows in a DataDescriptor that meet the specified criteria while checking for access rights:

Save

The ElasticSearchDao API helps you save a record from the memory into an ElasticSearch index. If a unique ID is included in the record and the record is listed in the index with the same unique ID, the previous data items are overwritten with the ones in the specified record. If specified record does not have a unique ID or there are no data items with the same unique ID in the index, then a new record is inserted into the index.

If you use an ElasticSearch DataDescriptor to save the record and you also specify the client object, the user's access rights are checked before saving the record. If the user is not authorized to save a record, the process is aborted, data items are left unchanged and the process results in an error. If the user is authorized, the save operation is successful.

Saving a record to an entity:
Saving a record to an entity with access control:
Saving multiple records to an entity at the same time:
Saving multiple records to an entity at the same time, using access control:
Saving a record to a DataDescriptor:
Saving a record to a DataDescriptor with access control:
Saving multiple records to a DataDescriptor with access control:
Saving multiple records to a DataDescriptor with access control:

Remove

The ElasticSearchDao API allows you to removed records from a specified index. Before you remove an index, you must make sure that the record contains a unique ID. As the remove operation does not use any other data items in the record, it works even if only the unique ID is in the record. You can also remove a record using a data class or a DataDescriptor. If the process encounters an error, then a removal error is returned and all data are left unchanged in the index.

Deleting a record from an entity:
Deleting multiple records from an entity at the same time:
Deleting a record from a DataDescriptor:
Deleting multiple records from a DataDescriptor: