Connecting to the ElasticSearch server
In order to access the data in an ElasticSearch server, first you have to connect to the server. You only have to connect to the server once, since once a connection is open, it remains active until it is closed. Implement the connection in the Startup class.
To implement the connection, specify the server name, IP address and port. The default address and port for the ElasticSearch is localhost:9300. Write the following code to implement the connection:
Disconnecting from an ElasticSearch server
Just like all database server connections, you have to close an ElasticSearch server connection before you quit the application. Do this in the shutdown() method of the Startup class, as this method is executed before each application shutdown. Use the following statement to disconnect from the server:
ElasticSearch entity class
The entity class used by the ElasticSearch plugin is very similar to that used by the JPA DAO. You have to create a POJO class and describe the physical data structure (ElasticSearch index attributes and the corresponding parameters).
Here's an example for an ElasticSearch entity class: