Connecting to OpenSearch Using cURL
In this example, we will use curl command to communicate with the OpenSearch cluster.
Prerequisites
Before making a curl request to the cluster, you first need to add your public IP to your cluster firewall rules. For more details on how to connect to your cluster click here.
1. The following command demonstrates how to create a user.
1 2 3 4 5 6 7 8 9 | curl -X PUT -u icopensearch:<Password> --cacert cluster-ca-certificate.pem https://xxx.xxx.xxx.xxx:9200/_plugins/_security/api/internalusers/my_user -H 'Content-Type: application/json' -d' { "password": "my_password", "backend_roles": [], "attributes": { "attribute1": "value1", "attribute2": "value2" } }' |
2. The following command demonstrates how to map a role to the user created above.
1 2 3 4 | curl -X PUT -u icopensearch:<Password> --cacert cluster-ca-certificate.pem https://xxx.xxx.xxx.xxx:9200/_plugins/_security/api/rolesmapping/readall_and_monitor -H 'Content-Type: application/json' -d' { "users" : [ "my_user" ] }' |
3. The following command demonstrates how to change the password for a user.
1 2 3 4 | curl -X PUT -u icopensearch:<Password> --cacert cluster-ca-certificate.pem https://xxx.xxx.xxx.xxx:9200/_plugins/_security/api/internalusers/my_user -H 'Content-Type: application/json' -d' { "password": "my_new_password" }' |
4. The following command demonstrates how to index a document (The index ‘testing’ will automatically be created if it does not exist).
1 2 3 4 5 | curl -X PUT -u icopensearch:<Password> --cacert cluster-ca-certificate.pem "https://xxx.xxx.xxx.xxx:9200/testing/_doc/1?pretty" -H 'Content-Type: application/json' -d' { "description" : "this is a test", "timestamp" : "2020-01-16T04:32:49" }' |
5. The following command demonstrates how to retrieve the document indexed in the previous step.
1 | curl -u icopensearch:<Password> --cacert cluster-ca-certificate.pem "https://xxx.xxx.xxx.xxx:9200/testing/_doc/1?pretty" |
Need Support?
Experiencing difficulties on the website or console?
Already have an account?
Need help with your cluster?
Contact Support Why sign up?
Spin up a cluster in minutes