X-Pack Info API

edit

Execution

edit

General information about the installed X-Pack features can be retrieved using the xPackInfo() method:

XPackInfoRequest request = new XPackInfoRequest();
request.setVerbose(true);          
request.setCategories(EnumSet.of(  
        XPackInfoRequest.Category.BUILD,
        XPackInfoRequest.Category.LICENSE,
        XPackInfoRequest.Category.FEATURES));
XPackInfoResponse response = client.xpack().info(request, RequestOptions.DEFAULT);

Enable verbose mode. The default is false but true will return more information.

Set the categories of information to retrieve. The default is to return no information which is useful for checking if X-Pack is installed but not much else.

Response

edit

The returned XPackInfoResponse can contain BuildInfo, LicenseInfo, and FeatureSetsInfo depending on the categories requested.

BuildInfo build = response.getBuildInfo();                 
LicenseInfo license = response.getLicenseInfo();           
assertThat(license.getExpiryDate(), is(greaterThan(Instant.now().toEpochMilli())));  
FeatureSetsInfo features = response.getFeatureSetsInfo();  

BuildInfo contains the commit hash from which Elasticsearch was built and the timestamp that the x-pack module was created.

LicenseInfo contains the type of license that the cluster is using and its expiration date.

Basic licenses do not expire and will return this constant.

FeatureSetsInfo contains a Map from the name of a feature to information about a feature like whether or not it is available under the current license.

Asynchronous Execution

edit

This request can be executed asynchronously:

client.xpack().infoAsync(request, RequestOptions.DEFAULT, listener); 

The XPackInfoRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for XPackInfoResponse looks like:

ActionListener<XPackInfoResponse> listener = new ActionListener<XPackInfoResponse>() {
    @Override
    public void onResponse(XPackInfoResponse indexResponse) {
        
    }

    @Override
    public void onFailure(Exception e) {
        
    }
};

Called when the execution is successfully completed. The response is provided as an argument

Called in case of failure. The raised exception is provided as an argument