How does set_default_index_prefix('foo_') works? #32
-
Hi, I'm not sure I understand how the method set_default_index_prefix('foo_') is supposed to work. Should it be called in the model? Before the connexion? I tried to put it everywhere but nothing seems to work, the prefix used to store my class is always esorm. Here's my very simple use case: class Profile(ESModel)
username: str = Field(frozen=True)
profile_name: str = Field(frozen=True)
config: list[dict] = Field(default_factory=list)
if __name__ == "__main__":
set_default_index_prefix('foo_')
asyncio.run(connect("http://localhost:9200"))
set_default_index_prefix('foo_')
profile = Profile(username="test_username", profile_name="test_profile_name",
config=[{"test": "foo", "columns": [{"name": "the column name"}]}])
asyncio.run(profile.save()) The newly created index is name |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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()) |
Beta Was this translation helpful? Give feedback.
-
Thanks! I didn't think of that... |
Beta Was this translation helpful? Give feedback.
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.