-
Multiple DocumentsBackEnd/Elasticsearch API 2025. 3. 10. 01:00반응형
_update_by_query
- To update documents in Elasticsearch based on a query, you can use the _update_by_query API.
# 모든 Documents를 업데이트 합니다. POST /store/_update_by_query { "script": { "source": "ctx._source.stock-=1" } } # product가 peach인 Documents만 업데이트 합니다. POST /store/_update_by_query { "script": { "source": "ctx._source.stock-=1" }, "query": { "term": { "product": "peach" } } }
_delete_by_query
- To delete documents in Elasticsearch based on a query, you can use the _delete_by_query API.
POST /store/_delete_by_query { "query": { "term": { "product": "apple" } } }
Bulk actions
- Bulk actions in Elasticsearch are a way to perform multiple index, update, delete, or create operations in a single API call.
Action Type
- Index: Adds or updates a document. If the document already exists, it will be replaced.
- Update: Partially updates a document. If the document does not exist, you can use upsert to create it.
- Delete: Deletes a document by its ID.
- Create: Adds a new document. If the document already exists, the operation will fail.
POST /_bulk { "index" : { "_index" : "store", "_id" : "10" } } { "product" : "apple", "stock" : 5 } { "update" : { "_index" : "store", "_id" : "10" } } { "doc" : { "stock" : 6 } } { "index" : { "_index" : "store", "_id" : "11" } } { "product" : "banana", "stock" : 5 } { "index" : { "_index" : "store", "_id" : "11" } } { "product" : "banana", "stock" : 10 } { "index" : { "_index" : "store", "_id" : "12" } } { "product" : "pear", "stock" : 10 } { "delete" : { "_index" : "store", "_id" : "12" } } POST /store/_bulk { "index" : { "_id" : "13" } } { "product" : "milk", "stock" : 1 }
[참고자료]
반응형'BackEnd > Elasticsearch API' 카테고리의 다른 글
Mapping parameters (0) 2025.03.14 Mapping (0) 2025.03.13 Analysis (0) 2025.03.11 Document (0) 2025.03.09 Introduction (0) 2025.03.08