We recently announced the general availability of our Elasticsearch Service API. APIs help to automate tasks such as creating and scaling deployments, integrating with existing workflows, and testing.
The Elasticsearch Service API supports the Open API Specification, which allows you to use tools like Swagger to generate software development kits (SDKs) in any programming language. You can import the API spec onto Postman and create a Postman Collection to create a test suite.
In this blog post, we’ll generate an SDK using Swagger and demonstrate how you can perform operations using the Elasticsearch Service API.
Generating an SDK
Note: If you don’t want to generate an SDK, you can skip this step and use the ESS Java Client SDK.
As mentioned above, the Elasticsearch Service API follows the Open API Specification. Here, we’ll be using Swagger Generator to generate respective language SDK.
- First, copy the API specification from this link.
- Open https://editor.swagger.io.
- Paste the API spec in the above link and accept the prompt to convert to YAML.
- Go to Generate Client > Java (we’ll select Java for this tutorial, but you can use the programming language of your choice).
Creating an API key
To perform any of the API calls, we need an API key to talk to Elasticsearch Service securely. This requires an Elastic Cloud account. Visit this link to spin up an extended 30-day free trial of Elastic Cloud.
Now you’ll need to create an API key using the Elastic Cloud console. You can do this under the Account section:
Note: API keys are sensitive and tied to your account, and they grant privileges to create, list, and destroy resources in Elasticsearch Service. Please keep your keys safe.
Performing operations using the Elasticsearch Service API and SDK
The Elasticsearch Service API contains multiple operation APIs to manage your deployments.
For example, we can use the SDK to automate essential workflows. I’m using Intellij and a sample Java project to use the SDK jar that we generated earlier. You can also use other editors to do the same thing.
Here are some operations you can perform with the Elasticsearch Service API SDK:
- Create an Elasticsearch Service deployment
- List Elasticsearch Service deployments
You can also see the API request equivalent to what you’ve configured in the user interface after selecting the required deployment specifications along with the cloud platform and region.
To see the list of available regions, refer to the available regions page in our documentation.
Thanks for following along! The code for this project is available in this GitHub repository.If you have any further questions, please do not hesitate to reach out on our community Slack channel #dev-cloud-api (request an invite here) or drop a question on our forums.