ElasticSearch in REST API

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.