The
main content of this article:
1 common operations for ElasticSearch
2 ElasticSearchBulk Command
ES REST API
The Elasticsearch supports a variety of communications, including the HTTP request response service, so you can send HTTP requests with the Curl command and get the JSON return content.
Common REST requests are:
Check cluster status
Curl Localhost:9200/_cat/health?v
Check node status
Curl Localhost:9200/_cat/nodes?v
Query all Indexes
Curl Localhost:9200/_cat/indices?v
Note: The cluster status is divided into green yellow red three states, green for health, yellow for data integrity but there is a problem with the copy, red indicates that the data is incomplete. In this case, the cluster is two nodes, the other node is not open, so the state is yellow.
Create an index
Curl-xput localhost:9200/index name/type/id-d {//json format body}
Delete Index
Curl-xdelete Localhost:9200/Index Name
Query index
Curl-xget localhost:9200/index name/type/ID
ES using bulk to add data
Use the bulk command to add data from the JSON file.
1. Create a new JSON file, Accounts.json, to define the JSON data format, where each data format is as follows:
{ "index": {"_id": "1"} "Account_number": 0, "balance": 16623, "FirstName": "Bradshaw", "LastName": "Mckenzie", "age": "gender": "F", "address": "244 Columbus Place", "Employer": "Euron" , " Email ":" [email protected] ,"City": "Hobucken", "state": "CO" }
2. Execute the commands and add them in bulk:
Curl-xpost ' Localhost:9200/bank/account/_bulk?pretty '--data-binary "@accounts. JSON"
3. Querying the Index
Curl ' localhost:9200/_cat/indices?v '
Indicates that we have successfully bulk import 1000 data indexes into the bank index.
ElasticSearch in REST API