我希望以编程方式获取ElasticSearch集群上安装的插件列表。虽然没有一种特定的方法可以使用其他API(我发现)实现这一点,但我能够使用REST接口提出解决方案;但是,我想知道是否有办法使用JavaAPI实现这一目标。
答案 0 :(得分:2)
应该是这样的:
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
...
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "es160").build();
final Client client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));
NodesInfoResponse nodesInfoResponse = client.admin().cluster().prepareNodesInfo().clear().setPlugins(true).get();
for (PluginInfo pluginInfo : nodesInfoResponse.getNodes()[0].getPlugins().getInfos()) {
System.out.println(pluginInfo.getName());
}
...