Home  >  Article  >  Java  >  How to implement elasticsearch java client action

How to implement elasticsearch java client action

WBOY
WBOYforward
2023-05-22 08:43:501503browse

Most operations in elasticsearch are through corresponding actions, which are in the action package. Its structure is shown in the figure below:

How to implement elasticsearch java client action

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

How to implement elasticsearch java client action

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:

How to implement elasticsearch java client action

#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.

How to implement elasticsearch java client action

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 transportAction = actions.get((ClientAction)action) Its function is to get the TransportAction based on the action. Because action is just a proxy. The implementation of these associations is carried out in the ActionModule, as demonstrated in the following code:

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete