ES Test
Once the ES cluster is successfully created (refer to the operation guide for creation), you can perform a preliminary test for the availability of the cluster. Here is an example of testing via a uhost that can access ues by using the curl command.
Cluster Status Test
curl -s -XGET 'http://<host>:9200/_cluster/health?pretty'
In normal circumstances, the system returns the result:
{
"cluster_name" : "ues-qwerty",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 1,
"active_shards" : 2,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
This indicates that the cluster is in a normal operation state, and then proceed to test data entry.
Index a Document
For example, the index is “test_index”, the type is “information”, and “1” is chosen as the ID number. At this time, the request is like this:
curl -X PUT \
http://<host>:9200/test_index/information/1 \
-H 'Content-Type: application/json' \
-d '{
"name": "test_index",
"age": 5,
"about": "at shanghai",
"interests": ["service"]
}'
Successful creation returns
{"_index":"test_index","_type":"information","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"created":true}
Retrieve Document
curl -X GET 'http://<host>:9200/test_index/information/1'
Returns
{"_index":"test_index","_type":"information","_id":"1","_version":1,"found":true,"_source":{
"name" : "test_index",
"age": 5,
"about": "at shanghai",
"interests": ["service"]
}}
Search Document
curl -X GET 'http://<host>:9200/_search'
curl -X GET 'http://<host>:9200/test_index/_search'
curl -X GET 'http://<host>:9200/test_index/information/_search'
curl -X GET "http://<host>:9200/_sql" -H 'Content-Type: application/json' -d'select * from test_index limit 10'
Complex Search
Complex search requires the use of POST method, for details please refer to the Function Document API Document.
Update Document
curl -X PUT \
http://<host>:9200/test_index/information/1 \
-H 'Content-Type: application/json' \
-d '{
"name" : "test_index",
"age": 5,
"about": "at shanghai",
"interests": ["service", "professional"]
}'
Successful update returns
{"_index":"test_index","_type":"information","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false}
Delete
Delete document
curl -X DELETE 'http://<host>:9200/test_index/information/1'
Delete specified type document
curl -X DELETE 'http://<host>:9200/test_index/information'
Delete index
curl -X DELETE 'http://<host>:9200/test_index'