curl Commands in Linux
Security Mode
The Solr client must be downloaded and installed before running curl commands on Linux. For details about how to download and install the client, refer to the Solr client installation guide.
- For security purpose, Solr only supports the TLSv1.2 protocols because it uses the SSL encryption mode. If you run the curl command to access Solr through HTTPS, the curl command also needs to support the TLSv1.2 protocols.
You can also configure Solr to support the TLSv1 and TLSv1.1 protocols. Choose Cluster > Name of the desired cluster > Services > Solr. Click Configurations then All Configurations. In the Search box, search for DISABLE_TLSV1_PROTOCOL, select false for all SolrServer instances, click Save, and click OK. Then restart the Solr service.
- You are advised to limit the alias name and collection name at 255 characters while creating a collection, otherwise it might affect the performance of ZooKeeper and Solr. For more information please refer to Solr service configuration SOLR_COLLECTION_CORE_MAX_LENGTH.
- In an IPv6 environment, add the -6 -g parameter to the curl command. For example, run the following command to create a collection:
curl --negotiate -6 -g -k -v -u : "https://hostname:port/solr/admin/collections?action=CREATE&name=test1&collection.configName=confWithSchema&numShards=3&replicationFactor=1"
-6: notifies cURL of resolving the address to an IPv6 address. -g: indicates that the URL global parser is disabled, that is, the URL can contain {}[].
- In openSUSE Leap 15.4, the shared link library files on the HDFS client are incompatible with curl commands. Download and install the Solr client separately and then run curl commands.
- Creating a collection
curl --negotiate -k -v -u : "https://hostname:port/solr/admin/collections?action=CREATE&name=test1&collection.configName=confWithSchema&numShards=3&replicationFactor=1"
- Run the following command to add a document to a collection:
curl --negotiate -k -v -u : -H "Content-Type: application/xml" -d "<add><doc boost=\"1.0\"><field name=\"id\">1</field><field name=\"name\">Zhang San</field></doc></add>" "https://hostname:port/solr/test1/update?wt=json&commit=true"
- Run the following command to add a document from a file to a collection:
curl "https://hostname:port/solr/test1/update" --negotiate -k -v -u : -H "Content-Type: text/xml" --data-binary @/tmp/test.xml
- Querying collections
curl --negotiate -k -v -u : "https://hostname:port/solr/test1/select?q=*&wt=json&indent=true"
- Run the following command to delete collection data:
curl --negotiate -k -v -u : "https://hostname:port/solr/test1/update" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
- Deleting a collection
curl --negotiate -k -v -u : "https://hostname:port/solr/admin/collections?action=DELETE&name=test1"
Common Mode
You can log in to any node of the Solr cluster, and run curl commands in a Linux OS.
- Log in to Manager and choose Cluster > Name of the desired cluster > Cluster Properties, and check whether Authentication Mode is Normal mode.
- You are advised to limit the alias name and collection name at 255 characters while creating a collection, otherwise it might affect the performance of ZooKeeper and Solr. For more information please refer to Solr service configuration SOLR_COLLECTION_CORE_MAX_LENGTH.
- In an IPv6 environment, add the -6 -g parameter to the curl command. For example, run the following command to create a collection:
curl --negotiate -6 -g -k -v -u : "https://hostname:port/solr/admin/collections?action=CREATE&name=test1&collection.configName=confWithSchema&numShards=3&replicationFactor=1"
-6: notifies cURL of resolving the address to an IPv6 address. -g: indicates that the URL global parser is disabled, that is, the URL can contain {}[].
- In openSUSE Leap 15.4, the shared link library files on the HDFS client are incompatible with curl commands. Download and install the Solr client separately and then run curl commands.
- Run the following command to create a collection:
curl "http://hostname:port/solr/admin/collections?action=CREATE&name=test1&collection.configName=confWithSchema&numShards=3&replicationFactor=1"
- Run the following command to add a document to a collection:
curl -H "Content-Type: application/xml" -d "<add><doc boost=\"1.0\"><field name=\"id\">2</field><field name=\"name\">Zhang San</field></doc></add>" "http://hostname:port/solr/test1/update?wt=json&commit=true"
- Run the following command to add a document from a file to a collection:
curl "http://hostname:port/solr/test1/update" -H "Content-Type: text/xml" --data-binary @/tmp/test.xml
- Run the following command to query a collection:
curl "http://hostname:port/solr/test1/select?q=*&wt=json&indent=true"
- Run the following command to delete collection data:
curl "http://hostname:port/solr/test1/update" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
- Run the following command to delete a collection:
curl "http://hostname:port/solr/admin/collections?action=DELETE&name=test1"
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