Introduction to Elasticsearch index additions and deletions

Source: Internet
Author: User

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

Format of the RESTful interface URL:

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

where index, type must be provided.

The ID is optional and does not provide ES will be generated automatically.

Index, type hierarchies information to facilitate management.

Index can be understood as a database; Type is interpreted as a data table; ID is equivalent to the primary key of a record in a database table.

Creation of indexed documents

Submit data for the following song information to the ES to create an index:

[Plain]View plain copy
    1. Url:http://127.0.0.1:9200/song001/list001/1
    2. data:{"number": 32768, "singer": "Yang Kun", "Size": "5109132", "Song": "20 years old Tonight", "tag": "China good Voice", "Timelen": 319}

The index name is: song001;

The type of index is: list001;

The ID of this record is: 1

The information returned can see that the creation was successful, and the version number is 1;es that the record modification is versioned, the first creation record is 1, and the same record is appended with 1 each time the modification is made.

At this point a record is submitted to ES to establish an index, note that the method of HTTP is put, do not choose the wrong.

Query for indexed documents

The restful interface for documents queried based on the ID of the index is as follows

Url:http://127.0.0.1:9200/song001/list001/1
The HTTP method takes the form of get.

Updating an indexed document

The contents of the document are updated according to the ID of the index when its restful interface is as follows

Url:http://127.0.0.1:9200/song001/list001/1
The HTTP method takes the form of put.

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

The version field in the result is already 2 because we are modifying, the index version is incremented, and the created field is false, which means the update is not new.

The update interface is exactly the same as creating an interface, ES queries the record for existence, if it does not exist, it is created, and the update operation exists.

Deletion of indexed documents

The contents of the document are updated according to the ID of the index when its restful interface is as follows

Url:http://127.0.0.1:9200/song001/list001/1
The HTTP method takes the form of delete.

After the deletion, the query interface to query will not get results.

Summarize:

Delete and change the RESTful interface URL form:http://localhost:9200/<index>/<type>/[<id>]

Introduction to Elasticsearch index additions and deletions

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.