Continue from section 7
5. Delete document & index
Delete type | Method or path parameter |
---|---|
Delete document | DELETE customer/external/1 |
Delete index | DELETE customer |
5.1, delete documents
Use the delete method to send the postman in the http://192.168.56.10:9200/customer/external/1
request, you can see the results, you can see the deleted documents Success:
A retransmission request 404 returns a status of not_found
the results:
Query the document just deleted, it will return a "found": false
404 status result:
5.2, delete the index
Use the delete method to send the postman in the http://192.168.56.10:9200/customer
request, you can see the results, you can see that the index is successfully deleted:
A retransmission request 404 returns a status of index_not_found_exception
the results:
Query the index just deleted, it will return a no such index [customer]
404 status result:
So the question is, since the
文档
sum can be deleted索引
, can it be deleted类型
?In ES, there are many types under an index, but ES does not provide a method to delete types. If an index is deleted, all types will be deleted.
6. Bulk API
operating | parameter |
---|---|
POST customer/external/_bulk |
{“index” {"_id":“1”} {“name”: “John Nash”} {“index”:"_id"2"} {“name”: “Jane Nash”} |
Grammar format | {action: {metadata}}\n {request body}\n {action: {metadata}}\n {request body}\n |
Complex instance POST /_bulk |
{“delete”:{"_index":“website”,"_type":“blog”,"_id":“123”}} {“create”:{"_index":“website”,"_type":“blog”,"_id":“123”}} {“title”:“My first blog post”} {“index”:{"_index":“website”,"_type":“blog”}} {“title”:“My second blog post”} {“update”:{"_index":“website”,"_type":“blog”,"_id":“123”}} {“doc”:{“title”:“My updated blog post”}} |
To use the bulk API, we need to perform our operations in kibana. If you request an error in postman, an error will be reported:
first of all, the data in our request body is not in json format. We use text format and will report the following error :
Let's change to json and try again: the
above json format is wrong, modify and try again:
you can see that bulk operations cannot be completed in postman, we need to operate in the previously installed kibana.
Open the console of kibana and select DevTools
:
Click after DevTools
the data interface. We are here to perform data operations:
Use DevTools
to perform batch operations, see the following results:
Perform a complex batch operation:
POST /_bulk
{"delete":{"_index":"website","_type":"blog","_id":"123"}}
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"123"}}
{"doc":{"title":"My updated blog post"}}
Used directly above /_bulk
, without specifying a specific index, it means that it is executed globally in ES. The results are as follows:
The bulk API executes all action
(actions) in this order .
If a single action fails for any reason, it will continue to process the remaining actions after it.
When the bulk API returns, it will provide the status of each action (same order as sent), so you can check whether a specified action has failed.
7. Sample test data
I prepared a sample of a fictitious JSON document of customer bank account information. Each document has the following schema (mode):
schema |
---|
{
“account_number”: 1, “balance”: 39225, “firstname”: “Amber”, “lastname”: “Duke”, “age”: 32, “gender”: “M”, “address”: “880 Holmes Lane”, “employer”: “Pyrami”, “email”: “[email protected]”, “city”: “Brogan”, “state”: “IL” } |
The above data is intercepted from ES official documents on github, you can visit the following address:
accounts.json import test data
Execute test data in ES
POST bank/account/_bulk
:
If it is not easy to copy data on github, you can use the data I downloaded: accounts.json , or visit gitee-accounts.json
After creation, you can use http://192.168.56.10:9200/_cat/indices
it to check the current index in ES. You can see that the index with bank has 1000 data:
reference:
Getting started with the full-text search engine Elasticsearch