mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 07:05:00 +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.
|
||||
func (idx *index) Put(uniqueID string, doc interface{}) (string, error) {
|
||||
body, err := json.Marshal(doc)
|
||||
docBytes, err := json.Marshal(doc)
|
||||
if err != nil {
|
||||
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,
|
||||
Body: bytes.NewReader(body),
|
||||
DocumentID: uniqueID,
|
||||
|
||||
Reference in New Issue
Block a user