Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: support bulk updates #87

Open
slint opened this issue Jun 28, 2018 · 0 comments
Open

api: support bulk updates #87

slint opened this issue Jun 28, 2018 · 0 comments

Comments

@slint
Copy link
Member

slint commented Jun 28, 2018

Currently, the API supports bulk index and delete. It would be nice to have a bulk_update, which would allow partial updates to indexed documents. The API calls could look something like this:

class RecordIndexer(object):
...
    def bulk_update(self, record_patch_iterator):
        # record_patch_iterator is a iterable of 2-tuples with a record UUID 
        # and a dictionary with the patch/update (see example below)
        self._bulk_op(record_patch_iterator, 'update')

    def _bulk_op(self, record_id_iterator, op_type, index=None, doc_type=None):
        with self.create_producer() as producer:
            if op_type == 'update':
                for rec, patch in record_id_iterator:
                producer.publish(dict(
                    id=str(rec),
                    patch=patch,
                    op='update',
                    index=index,
                    doc_type=doc_type
                ))
            else:
                ...
    
    def _update_action(self, payload):
        ...
        return {
            '_op_type': 'delete',
            '_index': index,
            '_type': doc_type,
            '_id': payload['id'],
            'doc': payload['patch']
        }

RecordIndexer().bulk_update(
    ['<some-record-uuid>', {'_stats': {'views': 42, 'downloads': 420}}],
    ['<some-record-uuid>', {'_stats': {'views': 100, 'downloads': 200}}],
    ...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant