Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report