Skip to content

How to get only specific fields? #17

Discussion options

You must be logged in to vote

@heindrickdumdum0217

It is indeed possible:

async def test():
    import esorm    
    class Model(esorm.ESModel):
        f_int: int = 0
        f_str: str = 'a'
    
    await esorm.setup_mappings()
    
    doc = Model(f_int=1, f_str='b')
    doc_id = await doc.save()
    assert doc_id is not None
    
    doc = await Model.get(doc_id)
    assert doc.f_str == 'b'
    assert doc.f_int == 1
    
    doc = await Model.search_one_by_fields(dict(_id=doc_id), _source=['f_str'])
    assert doc.f_str == 'b'
    assert doc.f_int == 0
    
    doc = await Model.search_one_by_fields(dict(_id=doc_id), _source=['f_int'])
    assert doc.f_str == 'a'
    assert doc.f_int == 1

Though get method has no _…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@heindrickdumdum0217
Comment options

@wallneradam
Comment options

Answer selected by wallneradam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #15 on August 02, 2024 09:33.