Most operations in elasticsearch are through corresponding actions, which are in the action package. Its structure is shown in the figure below:
Shown here is a partial screenshot of the Action package, which contains Actions corresponding to various functions. The packages of each action are also very similar to index. These actions all inherit from the base action, so their implementation is very similar. The following figure shows the inheritance relationship of indexaction
These actions are just substitutes and do not implement real functions, so they are also very easy to implement. Their main function is to provide methods for creating new responses and requests, corresponding to the corresponding operation names. Take indexaction as an example. Its method diagram is as follows:
#You can see that it only provides two methods for creating response and request, and a NAME field. , this NAME field will be used in subsequent action calls. The corresponding function is implemented in the corresponding transportAction.
TransportAction interface is inherited by all tansportAction. When the client calls the relevant interface of the client, the client will send the request to the execute of transportAction. The TransportAction of each function implements the doExecute method, and the logic of the function is implemented in this method. We will not mention it here for now. The corresponding implementation will be seen in the subsequent functional analysis.
There is such a piece of code in the client analysis:
TransportAction
registerAction(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class); registerAction(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class); registerAction(NodesShutdownAction.INSTANCE, TransportNodesShutdownAction.class); registerAction(NodesRestartAction.INSTANCE, TransportNodesRestartAction.class); registerAction(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class); registerAction(ClusterStatsAction.INSTANCE, TransportClusterStatsAction.class); registerAction(ClusterStateAction.INSTANCE, TransportClusterStateAction.class); registerAction(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class)
Only part of the content is shown here, where the module will bind the corresponding action and TransportAction. In this way, when the client needs to receive a request, it will find the corresponding tansportAction instance according to the corresponding action instance, and the final request will be processed under them.
The above is the detailed content of How to implement elasticsearch java client action. For more information, please follow other related articles on the PHP Chinese website!