[ES from entry to actual combat] Eight, full-text search-ElasticSearch-entry-delete data & bulk operation import sample test data

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/1request, you can see the results, you can see the deleted documents Success:
Insert picture description here

A retransmission request 404 returns a status of not_foundthe results:
Insert picture description here

Query the document just deleted, it will return a "found": false404 status result:
Insert picture description here

5.2, delete the index

Use the delete method to send the postman in the http://192.168.56.10:9200/customerrequest, you can see the results, you can see that the index is successfully deleted:
Insert picture description here

A retransmission request 404 returns a status of index_not_found_exceptionthe results:
Insert picture description here

Query the index just deleted, it will return a no such index [customer]404 status result:
Insert picture description here

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 :
Insert picture description here

Let's change to json and try again: the
Insert picture description here
above json format is wrong, modify and try again:
Insert picture description here
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:
Insert picture description here

Click after DevToolsthe data interface. We are here to perform data operations:
Insert picture description here

Use DevToolsto perform batch operations, see the following results:
Insert picture description here

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:
Insert picture description here

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:
Insert picture description here

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/indicesit to check the current index in ES. You can see that the index with bank has 1000 data:
Insert picture description here


reference:

Elasticsearch Reference

elastic

Getting started with the full-text search engine Elasticsearch

Guess you like

Origin blog.csdn.net/runewbie/article/details/106315509