mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 17:41:13 +00:00
Use UpdateRequest to insert/update a document
Currently, `IndexRequest` is used to insert/update a document, which increases the version of the document every time IndexRequest.Do is called.
This commit is contained in:
@@ -180,12 +180,15 @@ func (idx *index) DeleteIndex() error {
|
|||||||
|
|
||||||
// Insert or update the document by ID.
|
// Insert or update the document by ID.
|
||||||
func (idx *index) Put(uniqueID string, doc interface{}) (string, error) {
|
func (idx *index) Put(uniqueID string, doc interface{}) (string, error) {
|
||||||
body, err := json.Marshal(doc)
|
docBytes, err := json.Marshal(doc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
body := byteJoin(`{"doc":`, docBytes, `}`)
|
||||||
|
|
||||||
req := esapi.IndexRequest{
|
// Use `UpdateRequest` here instead of `IndexRequest`.
|
||||||
|
// For a document with a given id, every call of IndexRequest.Do will increase the version of a document.
|
||||||
|
req := esapi.UpdateRequest{
|
||||||
Index: idx.name,
|
Index: idx.name,
|
||||||
Body: bytes.NewReader(body),
|
Body: bytes.NewReader(body),
|
||||||
DocumentID: uniqueID,
|
DocumentID: uniqueID,
|
||||||
|
|||||||
Reference in New Issue
Block a user