Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

ES plug-in development-- how to add your own dynamic settings

Shulou Source: shulou.com Published: 2022-06-03 02:43:23 09月15日 Update

ES, there is a class of parameters can be dynamically adjusted, such as the number of copies: number_of_replicas.

How do I add my own custom parameters in plug-in development?

In the plug-in entry, add onModule(ClusterModule).

public class ShgyPlugin extends Plugin { @Override public String name() { return "shgy-plugin"; } @Override public String description() { return "shgy plugin "; } public void onModule(ClusterModule module){ module.registerIndexDynamicSetting("index.custom_setting", new Validator() { @Override public String validate(String setting, String value, ClusterState clusterState) { if (value == null) { throw new NullPointerException("value must not be null"); } return null; } }); }}

Compile the code, install the plug-in, and test it with the following script:

curl -X PUT "localhost:9200/twitter/_settings" -H 'Content-Type: application/json' -d'{ "index" : { "custom_setting" : 2 }}'curl -XGET 'http://localhost:9200/twitter/_settings? pretty'

Parameters are used in code, usually in TransportAction, and the code snippet is as follows:

ClusterState clusterState = clusterService.state(); clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ); String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request); IndexMetaData indexMeta = clusterState.getMetaData().index(concreteSingleIndex); int sectionCnt = indexMeta.getSettings().getAsInt("index.custom_settings",-1);

That is, get clusterState through clusterService, then get IndexMetaData, and then get Settings.

Custom dynamic parameters, with the use of templates, do not need to manually create indexes frequently. This knowledge point should be summarized as part of ES plug-in development.

Tags: Plug-ins parameters code dynamic development frequent entry copy manual quantity is in fragment knowledge knowledge point index script test compile adjust Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB macOS Apple Linux