Using Elasticsearch from Scratch
This section describes how to use Elasticsearch from scratch, including how to update the client configuration file on the active management node of the cluster, and how to use the client to create, query, and delete indexes.
Prerequisites
The cluster runs properly and the Elasticsearch client has been installed in a directory, for example, /opt/client. The client directory in the following operations is only an example. Change it to the actual installation directory.
Procedure
- Use the client on a Master node.
- Log in to the node where the client resides as the client installation user and run the following command to switch to the client directory:
- Run the following command to configure environment variables:
- If the current cluster is in security mode, run the following command to authenticate the current user. The current user must have the Elasticsearch cluster permission. Configure the role with the corresponding permission and bind the role to the user. If the current cluster is in security mode, skip this step:
for example, run the command kinit elasticsearchuser.
- Run commands on the Elasticsearch client.
For details about how to use the curl command, see Running curl Commands in Linux.
- Security mode:
- Run the following command to create an index. indexName indicates the name of the index to be created. ip:httpport indicates the service IP address of a node in the Elasticsearch cluster and the SERVER_PORT of any Elasticsearch instance on this node.
curl -XPUT --tlsv1.2 --negotiate -k -u : 'https://ip:httpport/indexName'
Example: curl -XPUT --tlsv1.2--negotiate -k -u : "https://10.131.112.121:24100/my_index-1"
- Run the following command to query the created index:
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:httpport/indexName?pretty'
Example: curl -XGET --tlsv1.2 --negotiate -k -u : "https://10.131.112.121:24100/my_index-1?pretty"
- Run the following command to delete an index:
curl -XDELETE --tlsv1.2 --negotiate -k -u : 'https://ip:httpport/indexName'
For example: curl -XDELETE --tlsv1.2 --negotiate -k -u : 'https://10.131.112.121:24100/my_index-1'.
- In the command output, check whether the index has been deleted.
- Run the following command to create an index. indexName indicates the name of the index to be created. ip:httpport indicates the service IP address of a node in the Elasticsearch cluster and the SERVER_PORT of any Elasticsearch instance on this node.
- Normal mode:
- Run the following command to create an index. indexName indicates the name of the index to be created. ip:httpport indicates the service IP address of a node in the Elasticsearch cluster and the HTTP_PORT of any Elasticsearch instance on this node.
curl -XPUT "http://ip:httpport/indexName"
For example: curl -XPUT "http://10.131.112.121:24100/my_index-1".
- Run the following command to query the created index:
curl -XGET 'http://ip:httpport/indexName?pretty"
For example: curl -XGET 'http://10.131.112.121:24100/my_index-1?pretty'.
- Run the following command to delete an index:
curl -XDELETE 'http://ip:httpport/indexName'
Example: curl -XDELETE 'http://10.131.112.121:24100/my_index-1'
- In the command output, check whether the index has been deleted.
- Run the following command to create an index. indexName indicates the name of the index to be created. ip:httpport indicates the service IP address of a node in the Elasticsearch cluster and the HTTP_PORT of any Elasticsearch instance on this node.
- Security mode:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot