Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic operations of Elasticsearch documents

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report