Skip to content

Dynamically initializing Index-Name via a Decorator. #1121

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

Closed
gk-patel opened this issue Feb 15, 2019 · 2 comments
Closed

Dynamically initializing Index-Name via a Decorator. #1121

gk-patel opened this issue Feb 15, 2019 · 2 comments

Comments

@gk-patel
Copy link

Hi,

first of all thank you very much for this wonderful library, it has been an amazing experience developing with library.

My current version: 6.3.1

I am facing problems while trying to dynamically give Index-Name (and Meta-data) to a Document Class. I am basically trying to do this by creating a decorator. Here is my code,

# my decorator, which I want to use to decorate the Document Class
def init_index_name(Cls): 

    # some logic to dynamically derive the index-name 
    indexName = 'dynamic_index_name'

    # initize an object of class Index, with the derived index-name 
    idxObj = Index(name=indexName))

    #add Index property to the decorated Class
    idxObj.document(Cls)

    # initialize the Index in ES 
    Cls.init()

    return Cls

# my document class 
@init_index_name
class tempIndex(Document): 
    tag = Keyword(multi=True)
    value = Integer()

Using this code, I am unable to set my Index-Name, and I get the following Error,

File "/home/gpatel/anaconda3/lib/python3.6/site-packages/elasticsearch_dsl/index.py", line 289, in save
    current_settings = self.get_settings(using=using)[self._name]['settings']['index']
KeyError: '*'

Also, could you tell me how can I dynamically add "meta-data" to the Index I am creating. For example, if I want to add the version of my software that created the Index. Just to be on the same page, I am refering to this https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-meta-field.html.

Once again, thank you very much for the library and also, for your help with all the Issues.

@honzakral
Copy link
Contributor

This is a duplicate of #1091, closing this issue to keep the discussion in one place.

@gk-patel
Copy link
Author

Hi @honzakral,

You are right, my Issue is very similar to the other issue.

Nonetheless, their was a second small question at the end, and I wish you can still help me it. Specifically,

How can I dynamically add "meta-data" to the Index I am creating. For example, if I want to add the version of my software that created the Index. Just to be on the same page, I am refering to this https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-meta-field.html.

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

2 participants