By section 7

5. Delete documents & indexes

Delete the type Method or path parameters
Delete the document DELETE customer/external/1
Remove the index DELETE customer

5.1. Delete documents

Use the delete method in the postman send http://192.168.56.10:9200/customer/external/1 request, you can see the following result, can see delete documents success:

Sending the request again returns a not_FOUND in the 404 state:

A query for the deleted document will return a 404 status of “found”: false:

5.2 Drop index

Use the delete method in the postman send http://192.168.56.10:9200/customer request, you can see the following result, can see index was removed successfully:

Sending a second request returns an index_NOT_found_EXCEPTION result in a 404 state:

Select * from customer where no such index [customer] is 404;

The question is, if you can delete documents and indexes, can you delete types?

In ES, there are many types under an index, but ES does not provide a method to delete the type. Once an index is deleted, all types are deleted.

Bulk bulk API

operation parameter
POST

customer/external/_bulk
{“index” {“_id”:”1″}

{“name”: “John Nash”}



{“index”:”_id”2″}

{“name”: “Jane Nash”}
Syntax 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 execute our operations in Kibana. If the request is in Postman, an error will be reported. First, the data in the request body is not in JSON format.

Let’s try json again:

DevTools

Click to display the DevTools data operation interface. This is where we will perform data manipulation:

Using DevTools to perform batch operations, you can 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"}}
Copy the code

In the preceding example, /_bulk is used without specifying an index, indicating that the ES execution is global. The result is as follows:

The BULK API executes all actions in this order. If a single action fails for any reason, it continues to process the remaining actions that follow it. When the BULK API returns, it will provide the status of each action (in the same order it was sent), so you can check if a given action failed.

7. Sample test data

I prepared a sample fictitious JSON document with the customer’s bank account information. Each document has the following schema:

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 data above was taken from github’s ES official documentation and can be accessed at:

Json imports test data

Test data in ES POST Bank/Account / _BULK:

If copying data isn’t easy on Github, you can use the data I downloaded: accounts. Json, or go to Gadee-accounts

Created after the completion of the can use http://192.168.56.10:9200/_cat/indices to check the index of the ES, now you can see a bank index of 1000 pairs of data:


Reference:

Elasticsearch Reference

elastic

Full text Search Engine Elasticsearch tutorial