Use Postman to access and manage an Alibaba Cloud Elasticsearch cluster - Elasticsearch - Alibaba Cloud Documentation Center
All Products
Search
Document Center

Elasticsearch:Use Postman to access and manage an Alibaba Cloud Elasticsearch cluster

Last Updated:Sep 11, 2023

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.

    Note
    • In 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.

    Note

Procedure

  1. Log on to the Postman console.

  2. 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.

  3. Create an environment and switch to the environment.

    1. In the left-side navigation pane, click Environments and then click the image.png icon to create an environment. In this example, an environment named aliyun_Environment is created.

    2. In the upper-right corner of the page, select the aliyun_Environment environment.

    Note

    For more information about environments, see Managing environments.

  4. Create a collection.

    1. In the left-side navigation pane, click Collections and then click the image.png icon. In the New Collection field, enter a name for the collection. In this example, a collection named ES Collection is created.

    2. 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.

  5. 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.

    Note

    You 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.

  6. On the ES Request page, execute the request.

    1. Select a request method such as GET, POST, or PUT.

    2. Enter a URL that is in the http://<Public endpoint of the Elasticsearch cluster>:<Public port>/<Path>/<Query parameters> format.

    3. 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.

    4. Click Send next to the URL that you entered to execute the request.

    image.png
    Note

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

  1. 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
  2. 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"}
          }
    }
  3. 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 the product_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 named 2 in the product_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.

      image.png

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