The REST API includes several sample programs that demonstrate how to perform administrative and search tasks.
The sample programs are installed in the ES_INSTALL_ROOT/samples/rest directory. Documentation about the REST API is available in the ES_INSTALL_ROOT/docs/api/rest directory.
For the administration REST APIs, several sample REST API Java™ programs are provided. The programs illustrate two different methods of using the REST APIs: Apache HttpClient or Java API for XML Web Services (JAX-WS). The sample programs must be compiled and their class files are in the ES_INSTALL_ROOT/samples/rest/admin/es.admin.rest.jar file.
The following REST API sample programs for HttpClient are provided in the ES_INSTALL_ROOT/samples/rest/admin/com/ibm/es/admin/control/api/samples/commons directory:
The program builds the HTTP request based on the specified host name, port, method, collection ID, and other options. It uses the user name and password to perform authentication. With the HTTP request, the program obtains the HTTPMethod object that is executed by HttpClient. For the add and addMultiDocs functions, the program uses the file path of an existing file and some of the metadata of the document to add the file content as a document in the collection.
The usage statement is as follows:
DocumentExample -hostname host_name -port port -method method
-username user_name -password password -collectionId collection_ID
additional_parameters
The following example shows how to add the content of the C:\samples\sample1.txt file as an English document in the col_12345 collection:
DocumentExample -hostname es.ibm.com -port 8390 -method add
-username user1 -password mypassword -collectionId col_12345
-language en -file C:\samples\sample1.txt
The program builds the HTTP POST request based on the specified host name, port, collection ID, and other parameters. The program specifies the document ID, title, format, and language of the documents in JSON format as the value of the docs parameter and the content of the documents is specified as the value of the file parameter. The program uses the specified user name and password to perform authentication. With the HTTP request, the program obtains the HTTPMethod object that is executed by HttpClient.
The usage statement is as follows:
AddMultiDocsExample -hostname host_name -port port -username user_name
-password password -collectionId collection_ID
The following example shows how to add the documents to the col_12345 collection:
AddMultiDocsExample -hostname es.ibm.com -port 8390 -username user1
-password mypassword -collectionId col_12345
It builds the HTTP Request URL based on the inputted host name, port, method, and other options. It uses the inputted user name and password to perform authentication. With the HTTP request, the program obtains the HTTPMethod object that is executed by HttpClient.
The usage statement is as follows:
FieldExample -hostname host_name -port port -method method
-username user_name -password password additional_parameters
The following shows an example of obtaining a list of fields for the col_12345 collection:
FieldExample -hostname es.ibm.com -port 8390 -method getList
-username user1 -password mypassword -collectionId col_12345
The usage statement is as follows:
GetAccess URL -username user_name -password password
The following example shows how to obtain the state of the index in xml format for the Test collection.
GetAccess "http://localhost:8390/api/v10/admin/indexer?
method=getState&output=xml&collectionId=Test" -username esadmin
-password password
The IndexerExample class shows how to perform various operations on the index, such as start and stop the index and get the state of the indexer. The type of function depends on the method that you input as a command argument.
The usage statement is as follows:
IndexerExample -hostname host_name -port port -method method
-username user_name -password password
The following example shows to start the index for the col_12345 collection.
IndexerExample -hostname es.ibm.com -port 8390 -username esadmin
-password password -method start -collectionId col_12345
The usage statement is as follows:
PearExample -hostname host_name -port port -method method
-username user_name -password password additional_parameters
The following example shows how to add the of_regex.pear PEAR file and name it RegexPear in Watson Explorer Content Analytics.
PearExample -hostname es.ibm.com -port 8390 -method add
-username esadmin -password password -pearName RegexPear
-content "C:\\IBM\\es\\packages\\uima\\regex\\of_regex.pear"
The following REST API sample programs for JAX-WS are provided in the ES_INSTALL_ROOT/samples/rest/admin/com/ibm/es/admin/control/api/samples/jaxws directory:
The usage statement is as follows:
FacetExample -hostname host_name -port port -method method
-username user_name -password password additional_parameters
The following example shows how to obtain a list of facets for the col_12345 collection.
FacetExample -hostname es.ibm.com -port 8390 -method getList
-username esadmin -password password -collectionId col_12345
The usage statement is as follows:
GetAccess URL
The following example shows how to obtain the state of the indexer for the Test collection.
GetAccess “http://localhost:8390/api/v10/admin/indexer?
method=getState&output=xml&collectionId=Test
&api_username=esadmin&api_password=password”
The usage statement is as follows:
PearExample -hostname host_name -port port -method method
-username user_name -password password additional_parameters
The following example shows how to add the of_regex.pear PEAR file and name it RegexPear in Watson Explorer Content Analytics.
PearExample -hostname es.ibm.com -port 8390 -method add
-username esadmin -password password -pearName RegexPear
-content "C:\\IBM\\es\\packages\\uima\\regex\\of_regex.pear"