Open source Elasticsearch provides a variety of RESTful APIs. You can run curl commands to call these APIs or use these APIs in Kibana or Postman. This topic describes how to use Postman to access and manage an Alibaba Cloud Elasticsearch cluster.
Prerequisites
Postman is installed.
NoteIn this example, the Postman 10.16.9 client is used. The GUI elements in the Postman console may vary based on the version of the Postman client.
To download Postman, visit Download Postman.
An Alibaba Cloud Elasticsearch cluster is created, the Public Network Access feature is enabled for the Elasticsearch cluster, and the IP address of the device on which Postman is installed is added to the public IP address whitelist of the Elasticsearch cluster.
NoteIn this example, an Elasticsearch V8.5.1 cluster is used. The operations that are required to access and manage an Elasticsearch cluster may vary based on the Elasticsearch version.
For information about how to configure the IP address whitelist of an Elasticsearch cluster, see Configure a public or private IP address whitelist for an Elasticsearch cluster.
Procedure
Log on to the Postman console.
In the left-side navigation pane, click New and select Workspace. On the page that appears, click Create Workspace to create a workspace.
In this example, a workspace named
test-workspaces
is created.Create an environment and switch to the environment.
In the left-side navigation pane, click Environments and then click the icon to create an environment. In this example, an environment named
aliyun_Environment
is created.In the upper-right corner of the page, select the
aliyun_Environment
environment.
NoteFor more information about environments, see Managing environments.
Create a
collection
.In the left-side navigation pane, click Collections and then click the icon. In the New Collection field, enter a name for the collection. In this example, a collection named
ES Collection
is created.On the ES Collection page, click the Authorization tab and configure authorization information.
Type: Select Basic Auth.
Username: Enter
elastic
, which is the username of the Elasticsearch cluster.Password: Enter the password of the Elasticsearch cluster.
Create a
request
.On the left side of the page, click ES Collection. Then, click Add a request. In the New Request field, enter a name for the request. In this example, a request named
ES Request
is created.On the ES Request page, click the Authorization tab. On the Authorization tab, select Basic Auth for the Type parameter.
NoteYou can create multiple requests in the collection. If you create multiple requests in the collection, you must select Basic Auth for the Type parameter on the Authorization tab for each request.
On the ES Request page, execute the request.
Select a request method such as GET, POST, or PUT.
Enter a URL that is in the
http://<Public endpoint of the Elasticsearch cluster>:<Public port>/<Path>/<Query parameters>
format.Optional. Enter a request body. Click the Body tab. On the Body tab, select raw, and select
JSON
from the drop-down list. In the code editor, enter a request body.Click Send next to the URL that you entered to execute the request.
NoteFor information about more operations, see Building requests.
For information about the commands that you can use to manage an Elasticsearch cluster, see Commands for managing an Elasticsearch cluster.
Commands for managing an Elasticsearch cluster.
This section describes the commands that you can use to manage an Elasticsearch cluster. For information about other commands, see open source Elasticsearch documentation.
View cluster information
Run the following command to query the health status of an Elasticsearch cluster:
GET http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/_cat/health?v
Run the following command to query indexes in an Elasticsearch cluster:
GET http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/_cat/indices?v
Create an index and documents
Create an index.
Run the following command to create an index named product_info:
PUT http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/product_info
Run the following command to configure mappings for the index:
PUT http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/product_info/_mapping { "properties": { "productName": {"type": "text","analyzer": "ik_smart"}, "annual_rate":{"type":"keyword"}, "describe": {"type": "text","analyzer": "ik_smart"} } }
Create documents and insert data records into the documents.
Create a single document and insert a data record into the document.
Run the following command to create a document named
1
in theproduct_info
index and insert a data record into the document:
POST http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/product_info/_doc/1 { "productName":"testpro", "annual_rate":"3.22%", "describe":"testpro" }
Create multiple documents and insert a data record into each document.
Run the following command to create a document named
1
and another document named2
in theproduct_info
index and insert a data record into each document:POST http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/_bulk { "index" : { "_index": "product_info", "_id" : "1" } } {"productName":"testpro","annual_rate":"3.22%","describe":"testpro"} { "index" : { "_index": "product_info", "_id" : "2" } } {"productName":"testpro1","annual_rate":"3.26%","describe":"testpro"}
When you call the
bulk
API in the Postman console to insert data records into multiple documents, you must make sure that a line feed is used at the end of each row of code for inserting a data record into each document and the last row of the entire code block is empty.
Search for a document
Run the following command to search for a document named 1
:
GET
http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/product_info/_doc/1?pretty
Delete an index
Run the following command to delete an index named product_info
:
DELETE
http://es-xxxxx.public.elasticsearch.aliyuncs.com:9200/product_info