Upsert in `update`
See original GitHub issueWould it make sense to tweak DocType.update()
to perform an upsert if the item doesn’t already exist (at https://github.com/elastic/elasticsearch-dsl-py/blob/master/elasticsearch_dsl/document.py#L227)?
meta = es.update(
index=self._get_index(index),
doc_type=self._doc_type.name,
body={'doc': fields, 'doc_as_upsert': True, 'detect_noop': True},
**doc_meta
)
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Upsert in MongoDB - GeeksforGeeks
In MongoDB, upsert is an option that is used for update operation e.g. update(), findAndModify(), etc. Or in other words, upsert is a ......
Read more >Guide to Upsert in MongoDB - Baeldung
Upsert is a combination of insert and update (inSERT + UPdate = upsert). We can use the upsert with different update methods, i.e.,...
Read more >Upsert in SQL: What is an upsert, and when should you use ...
The UPSERT command in CockroachDB performs an upsert based on the uniqueness of the primary key column or columns, and it will perform...
Read more >What's the difference between INSERT, UPDATE, UPSERT ...
The UPSERT option is the combination of 'Update' and 'Insert' which means that it will check for the records that are inserted or...
Read more >db.collection.update() — MongoDB Manual
Updates a single document that matches the query . If both upsert and multi are true and no documents match the query, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Example where upsert is convenient.
Lets assume I have simple document.
def Document(DocType): text = Text() read_counter = Integer()
Now consider that there is two separate programs that use this Document. One is indexing Documents without touching counter and other updates only counter. The later can assume that document always exist so I can use
document.update(read_counter=reads)
. I can’t do the same for first because what I need is to index document if it does not exist or update if it exists unfortunately document.save() will overwrite whole document thus read_counter is lost in process.I know I could get document first to check if it exists but the whole point of the update API in ES is to avoid that.
Otherwise why implementing update at all? I can always get instance, update some fields and save whole document.
so, how on earth update a doc like upsert? did you find a solution at last? is there a document tell us how to implement?
thanks!