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.
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
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:
Initiating a generic query using the ElasticSearch DataDescriptor:
Getting a record from the index using its unique ID:
Counting the records:
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.
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.