Discover how to effortlessly manage your Alibaba Cloud Elasticsearch cluster through API operations. This comprehensive guide provides essential insights into using curl commands and navigating API operations for accessing an Alibaba Cloud Elasticsearch cluster. You’ll learn to query cluster information, create indexes and documents, and execute document searches with ease.
Alibaba Cloud Elasticsearch: Please Click here, Embark on Your 30-Day Free Trial !!
The ability to run API operations through curl commands is a cornerstone for managing Alibaba Cloud Elasticsearch clusters. Whether you’re a beginner or an experienced user, the steps outlined here will guide you through seamless cluster access and management. For those looking to use the Kibana console for API operations, our dedicated section offers the detailed information you need.
You can refer to this topic to call API operations by running curl commands. For more information about how to call the API operations by using the Kibana console, see Log on to the Kibana console
An Elastic Compute Service (ECS) instance that runs the Linux operating system is created in the virtual private cloud (VPC) where your Alibaba Cloud Elasticsearch cluster resides. For more information, see Create an instance by using the wizard
Important
You can also use an existing ECS instance that resides in the same VPC as your Elasticsearch cluster.
1)Connect to the ECS instance.For more information, see Step 3: Connect to the ECS instance
NoteIn this example, a common user is used.
2)Run the following command to access your Elasticsearch cluster.
Note: If the system displays curl command not found, you must run the sudo yum install curl command to install cURL on the ECS instance.
curl -u <user>:<password> http://<host>:<port>
Variable | Description |
---|---|
<user> |
The username that is used to access your Elasticsearch cluster. We recommend that you use a username other than elastic.Important |
<password> |
The password that is used to access your Elasticsearch cluster. The password of the elastic account is specified when you create the Elasticsearch cluster. If you forget the password, you can reset it. For more information about the procedure and precautions for resetting the password, see Reset the access password for an Elasticsearch cluster. |
<host> |
The internal endpoint of your Elasticsearch cluster. You can obtain the internal endpoint from the Basic Information page of the Elasticsearch cluster. |
<port> |
The port number that is used to access your Elasticsearch cluster. The default port number is 9200. You can obtain the port number from the Basic Information page of the Elasticsearch cluster. |
Sample command:
curl -u <user>:<password> http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200
If the command is successfully run, the result shown in the following figure is returned.
1)If you use the elastic account to access your Elasticsearch cluster and then reset the password of the account, it may require some time for the new password to take effect. During this period, you cannot use the elastic account to access the cluster. Therefore, we recommend that you do not use the elastic account to access an Elasticsearch cluster. You can log on to the Kibana console, create a user with the required role, and access the Elasticsearch cluster as the user. For more information, see Use the RBAC mechanism provided by Elasticsearch X-Pack to implement access control
2)If the version of your Elasticsearch cluster contains with_X-Pack, you must specify both the username and password to access the Elasticsearch cluster.
1)Query the health status of the cluster
2)Query indexes in the cluster
curl -u <user>:<password> -XGET 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/_cat/health?v'
If the command is successfully run, the result shown in the following figure is returned.
curl -u <user>:<password> -XGET 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/_cat/indices?v'
If the command is successfully run, the result shown in the following figure is returned.
1)Create an index
2)Configure a mapping for an index
3)Create documents and insert data
curl -u <user>:<password> -XPUT 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/product_info'
In the preceding example, an index named product_info is created.If the command is successfully run, the result shown in the following figure is returned.
curl -u <user>:<password> -XPUT 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/product_info/_doc/_mapping?include_type_name=true' -H 'Content-Type: application/json' -d '
{
"_doc":{
"properties": {
"productName": {"type": "text","analyzer": "ik_smart"},
"annual_rate":{"type":"keyword"},
"describe": {"type": "text","analyzer": "ik_smart"}
}
}
}'
If the command is successfully run, the result shown in the following figure is returned.
In the preceding example, the type of the product_info index is set to _doc. The index contains the productName, annual_rate, and describe fields. If you use an Elasticsearch cluster of V7.0 or later, the type of indexes in the cluster must be _doc. This example also defines tokenizers for the fields.
curl -u <user>:<password> -XPOST 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/product_info/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"productName":"testpro",
"annual_rate":"3.22%",
"describe":"testpro"
}'
If the command is successfully run, the result shown in the following figure is returned.
In the preceding example, a document named 1 is created in the product_info index of the _doc type, and a data record is inserted into the document.
curl -u <user>:<password> -XPOST http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/_bulk -H 'Content-Type: application/json' -d'
{ "index" : { "_index": "product_info", "_type" : "_doc", "_id" : "1" } }
{"productName":"testpro","annual_rate":"3.22%","describe":"testpro"}
{ "index" : { "_index": "product_info", "_type" : "_doc", "_id" : "2" } }
{"productName":"testpro1","annual_rate":"3.26%","describe":"testpro"}'
If the command is successfully run, the result shown in the following figure is returned.
In the preceding example, documents named 1 and 2 are created in the product_info index of the _doc type, and a data record is inserted into each of the documents.
curl -u <user>:<password> -XGET 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/product_info/_doc/1?pretty'
If the command is successfully run, the result shown in the following figure is returned.
In the preceding example, a document named 1 is searched for.
curl -u <user>:<password> -XDELETE 'http://es-cn-vxxxxx****.elasticsearch.aliyuncs.com:9200/product_info'
If the command is successfully run, the result shown in the following figure is returned.
In the preceding example, an index named product_info is deleted.
Note
For information about other commands, see open source Elasticsearch documentation
Ready to start your journey with elasticsearch on Alibaba Cloud? Explore our tailored Cloud solutions and services to take the first step towards transforming your data into a visual masterpiece.Please Click here, Embark on Your 30-Day Free Trial !!
Learn more about New Features of Alibaba Cloud Elasticsearch
Migrating from AWS OpenSearch to Alibaba Cloud Elasticsearch: A Step-by-Step Guide
Top 30 Essential Knowledge Points You Need to Know About Elasticsearch
Data Geek - July 11, 2024
Data Geek - June 25, 2024
Data Geek - May 9, 2024
Data Geek - June 18, 2024
Data Geek - June 6, 2024
Data Geek - July 17, 2024
Alibaba Cloud Elasticsearch helps users easy to build AI-powered search applications seamlessly integrated with large language models, and featuring for the enterprise: robust access control, security monitoring, and automatic updates.
Learn MoreOpenAPI Explorer allows you to call an API through its web interface or WebCLI, and view the entire process.
Learn MoreAPI Gateway provides you with high-performance and high-availability API hosting services to deploy and release your APIs on Alibaba Cloud products.
Learn MoreHighly reliable and secure deployment solutions for enterprises to fully experience the unique benefits of the hybrid cloud
Learn MoreMore Posts by Data Geek