Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: read elastic search remote connection properties in my custom portlet
I want to read elastic search remote connection properties in my custom portlet from System Setting -> Search -> Elastic Search Connection. How can I do this?
I did this in a groovy script and ran it in the scripting console, but you should be able to replace both service trackers with @Reference to those services in your component class.
import com.liferay.portal.search.engine.ConnectionInformation;
import com.liferay.portal.search.engine.NodeInformation;
import com.liferay.portal.search.engine.SearchEngineInformation;
import com.liferay.portal.kernel.module.util.SystemBundleUtil;
import org.osgi.framework.Bundle;
import org.osgi.util.tracker.ServiceTracker;
ServiceTracker<SearchEngineInformation, SearchEngineInformation> st;
st = new ServiceTracker(SystemBundleUtil.getBundleContext(), SearchEngineInformation.class, null);
st.open();
SearchEngineInformation searchEngineInformation = st.waitForService(500);
st.close();
ServiceTracker<NodeInformation, NodeInformation> st2;
st2 = new ServiceTracker(SystemBundleUtil.getBundleContext(), NodeInformation.class, null);
st2.open();
NodeInformation nodeInformation = st2.waitForService(500);
st2.close();
List<ConnectionInformation> connectionInformationList = searchEngineInformation.getConnectionInformationList();
out.println("Vendor: " + searchEngineInformation.getVendorString());
out.println("Client Version: " + searchEngineInformation.getClientVersionString());
for (ConnectionInformation connectionInformation : connectionInformationList) {
List<NodeInformation> nodeInformationList = connectionInformation.getNodeInformationList();
out.println(" Cluster Name: " + connectionInformation.getClusterName());
out.println(" Connection ID: " + connectionInformation.getConnectionId());
out.println(" Error: " + connectionInformation.getError());
out.println(" Health: " + connectionInformation.getHealth());
out.println(" Labels: " + connectionInformation.getLabels());
out.println(" Nodes:");
for (NodeInformation nodeInformationItem : nodeInformationList) {
out.println(" Name: " + nodeInformationItem.getName());
out.println(" Version: " + nodeInformationItem.getVersion());
}
}
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™