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
|
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 theid
,name
, anddescribe
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" } }