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
- Url:http://127.0.0.1:9200/song001/list001/1
- 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