Introduction to adding, deleting, modifying, and querying elasticsearch index documents

Source: Internet
Author: User
1. Restful Interface Usage

For convenience and convenience, we use the interfaces provided by the head plug-in to demonstrate the restful interfaces actually called internally.


Restful interface URL format:

Http: // localhost: 9200/<index>/<type>/[<ID>]

Here, index and type are required.

The ID is optional. If elasticsearch is not provided, it is automatically generated.

The index and type layers the information to facilitate management.

Index can be understood as a database; type can be understood as a data table; ID is equivalent to the primary key recorded in the database table and is unique.

2. Create an index document and submit the data of the next song information to es to create an index:

URL: http: // 127.0.0.1: 9200/song001/list001/1 data: {"Number": 32768, "Singer": "Yang Kun", "size": "5109132 ", "Song": "", "tag": "Good voice in China", "timelen": 319}

The index name is song001;

The index type is list001;

The ID of this record is: 1

The returned information shows that the record is successfully created and the version number is 1. elasticsearch tracks the version of the record modification. The first record is created as 1, and the same record is appended with 1 each time it is modified.

At this point, a record is submitted to es to create an index. Note that the HTTP method is put. Do not select an error.

3. Index document Query

The Restful API of the document queried Based on the index ID is as follows:

URL: http: // 127.0.0.1: 9200/song001/list001/1
The HTTP method is in the get format.


4. Index document update

The Restful interface of the document updated based on the index ID is as follows:

URL: http: // 127.0.0.1: 9200/song001/list001/1
The HTTP method is in the put format.

Change the singer's name from "Yang Kun" to "Yang Kun solo ";

The version field in the result is 2, because this is a modification, and the index version increases progressively; The created field is false, indicating that this is not a new one but an update.

The update interface is exactly the same as the creation interface. elasticsearch queries whether a record exists.



5. Delete the index document

The Restful interface of the document updated based on the index ID is as follows:

URL: http: // 127.0.0.1: 9200/song001/list001/1
The HTTP method is in the form of Delete.

After deletion, no results will be obtained through the query interface.


Summary:

Add, delete, modify, and query restful interface URL:Http: // localhost: 9200/<index>/<type>/[<ID>]

The add, delete, modify, and query operations correspond to the put, get, and delete methods of HTTP requests. If a put call does not exist, the call is created, and the call is updated.


Introduction to adding, deleting, modifying, and querying elasticsearch index documents

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.