Skip to content

How does set_default_index_prefix('foo_') works? #32

Answered by wallneradam
Boris-Sachet asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, You should call it before you create the model. It is a global variable. And the model meta class uses it. So if you set it after the model declaration, the prefix is already set.

set_default_index_prefix('foo_')


class Profile(ESModel)
    username: str = Field(frozen=True)
    profile_name: str = Field(frozen=True)
    config: list[dict] = Field(default_factory=list)

if __name__ == "__main__":
    asyncio.run(connect("http://localhost:9200"))
    profile = Profile(username="test_username", profile_name="test_profile_name",
                      config=[{"test": "foo", "columns": [{"name": "the column name"}]}])
    asyncio.run(profile.save())

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by wallneradam
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #31 on July 24, 2025 11:20.