Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the basic operations of Elasticsearch documents

Shulou Source: shulou.com Published: 2022-06-01 12:41:51 11月13日 Update

This article will explain in detail what are the basic operations of Elasticsearch documents, the editor thinks it is very practical, so share it for you to do a reference, I hope you can get something after reading this article.

Basic addition, deletion, modification, query, create document / / create document, automatically generate idPOST / / _ doc {"foo": "bar"} / / create document and specify that id,id already exists, PUT / / _ doc/?op_type=create {"foo": "bar"} / / create document and specify that id,id already exists, error report PUT / / _ create/ {"foo": "bar"} get document GET / / _ doc/ modify document

Modify the entire document

PUT / / _ doc/ {"aaa": "bbb"}

Add field

POST / / _ update/ {"doc": {"newFoo": "newBar"}}

Regardless of the modification, the _ version field of the document is incremented by 1.

Bulk API

The bulk API of ES refers to the API that allows the requestor to do different things in one operation. For example, delete a document with id as qqq and create a document with id as www in one request, and the content of the new document is {"dd": "ff"}.

The operations supported by bulk API are:

Index

Create

Update

Delete

That is, all kinds of write operations are supported, and reading and writing in the same request are not supported.

The failure of a single operation does not affect others, and the returned result contains the execution result of each operation.

POST / _ bulk {"index": {"_ index": "myindex", "_ id": "3"} {"ccc", "mmm"} {"delete": {"_ index": "myindex", "_ id": "10"}}

In the above operation, you first create a document with id 3 in index myindex with line 2, and then delete the document with id 10 in index myindex.

Because two operations are performed, ResponseBody is a list with two elements, corresponding to the result of each operation.

Batch read GET / _ mget {"docs": [{"_ index": "myindex", "_ id": "3"}, {"_ index": "index22", "_ id": "234"},]}

The returned ResponseBody looks like this:

{"docs": [] / / request several documents Here are several} batch search POST / / _ msearch {} {"query": {"match_all": {}}, "size": 1} {"index": "index333"} {"query": {"match_all": {}}, "size": 2} this article on "what are the basic operations of Elasticsearch documents" is shared here. I hope the above content can be of some help to you. So that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Documents content articles results support basic operations fields more indexes different good practical that is elements foundations that is articles knowledge automatic generation faceted Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Linux NVidia vpn