All Products
Search
Document Center

Lindorm:Run curl commands to connect to and use LindormSearch

Last Updated:Jun 26, 2024

LindormSearch provides a series of RESTful APIs that are compatible with Elasticsearch. You can call the APIs by running curl commands to manage the search indexes and documents in LindormSearch.

Prerequisites

  • LindormSearch is activated for your Lindorm instance. For more information, see Activate LindormSearch.

  • The IP address of your client is added to the whitelist of your Lindorm instance. For more information, see Configure whitelists.

Connect to LindormSearch

Run the following command to connect to LindormSearch and view the information about the indexes in the cluster.

curl -XGET "http://<url>/_cat/indices?v" -u <username>:<password>  

Parameters

Parameter

Description

url

The LindormSearch endpoint for Elasticsearch. For more information about how to obtain the endpoint, see LindormSearch endpoint for Elasticsearch.

Important
  • If your application is deployed on an ECS instance, we recommend that you use a VPC to connect to the Lindorm instance to ensure higher security and lower network latency.

  • If your application is deployed on a local server and needs to connect to the Lindorm instance over the Internet, you can perform the following steps to enable the public endpoint of the instance in the Lindorm console: In the left-side navigation pane, click Database Connections. On the page that appears, click the Search Engine tab. Then, click Enable Public Endpoint in the upper-right corner.

  • If you use a VPC to access the Lindorm instance, specify the LindormSearch VPC endpoint for Elasticsearch in the value of url. If you use the Internet to access the Lindorm instance, specify the LindormSearch Internet endpoint for Elasticsearch in the value of url.

username

The username and password used to access LindormSearch.

You can perform the following steps to obtain the default username and password: In the left-side navigation pane, click Database Connections. On the page that appears, click the Search Engine tab. Then, view the username and password displayed on this tab.

password

The following command provides an example on how to connect to LindormSearch:

curl -XGET "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/_cat/indices?v" -u <username>:<password>

After you are connected to LindormSearch, the following results are returned. No index information is included in the results because no index is created in the cluster.

health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

Perform operations in LindormSearch

The following examples show how to use common curl commands to perform operations in LindormSearch. For more information about other commands, see Elasticsearch documentation.

Manage indexes

  • Creates an index.

    Create an index named lindorm_search in LindormSearch.

    curl -XPUT "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/lindorm_search" -u <username>:<password>

    After the index is created, the following result is returned:

    {"acknowledged":true,"shards_acknowledged":true,"index":"lindorm_search"}
  • Configure the schema of an index.

    Set the schema of lindorm_search to _mapping of the _doc type. The specified schema contains the id, name, and describe fields.

    curl -XPUT "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/lindorm_search/_doc/_mapping" -u <username>:<pasword> -H 'Content-Type: application/json' -d '
    {        
     "_doc":{
       "properties": {
            "id": {"type": "long"},
            "name":{"type":"keyword"},
            "describe": {"type": "text"}
          }
      }
    }'

    After the schema is configured, the following result is returned:

    {"_index":"lindorm_search","_type":"_doc","_id":"_mapping","_version":1,"result":"created","_shards":{"total":1,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
  • View the indexes of an instance.

    curl  -XGET "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/_cat/indices?v" -u <username>:<pasword>

    The following result is returned:

    health status index          uuid           pri rep docs.count docs.deleted store.size pri.store.size
    green  open   lindorm_search lindorm_search   1   0          0            0       208b           208b

    If no index is created for the current instance, no index information is included in the returned results.

  • Delete an index.

    curl -XDELETE "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/lindorm_search" -u <username>:<password>

    After the index is deleted, the following result is returned:

    {"acknowledged":true}

Manage documents

  • Create a single document.

    Create a document whose ID is 1 in the lindorm_search index.

    curl -XPOST "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/lindorm_search/_doc/1" -u <username>:<password> -H 'Content-Type: application/json' -d '
    { 
    "id":100,
    "name":"shenzhen",
    "describe":"just a test"
    }'
  • Create multiple documents.

    Create two documents whose IDs are 1 and 2 in the lindorm_search index.

    curl -XPOST "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/_bulk" -u <username>:<password> -H 'Content-Type: application/json' -d'
    { "index" : { "_index": "lindorm_search", "_type" : "_doc", "_id" : "1" } }
    {"id":200,"name":"shanghai","describe":"just"}
    { "index" : { "_index": "lindorm_search", "_type" : "_doc", "_id" : "2" } }
    {"id":300,"name":"beijing","describe":"dood luck"}
    '
  • Query a document.

    Query the document whose ID is 1.

    curl  -XGET "http://ld-t4n5668xk31ui****-proxy-search-public.lindorm.rds.aliyuncs.com:30070/lindorm_search/_doc/1?pretty" -u <username>:<password>

    The following result is returned:

    {
      "_index" : "lindorm_search",
      "_id" : "1",
      "_version" : 1,
      "_seq_no" : 0,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "id" : 100,
        "name" : "shenzhen",
        "describe" : "just a test"
      }
    }