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

Elasticsearch attribute name different from Python name #1345

Closed
lschmelzeisen opened this issue Apr 19, 2020 · 5 comments
Closed

Elasticsearch attribute name different from Python name #1345

lschmelzeisen opened this issue Apr 19, 2020 · 5 comments

Comments

@lschmelzeisen
Copy link

Hi, I currently have a document definition similar to the following:

class BlogPost(Document):
    title = Text()
    content = Text()
    type = Keyword()

However, my code style dictates that I avoid shadowing Python-interals, such as type() here.

Therefore, I'd like to change the name of the class attribute without changing the name in the Elasticsearch mapping. I'm thinking of syntax similar to the following:

class BlogPost(Document):
    title = Text()
    content = Text()
    type_ = Keyword(name="type")

Is something like this supported?

@lschmelzeisen
Copy link
Author

I just noticed that there is an even better reason for needing this. I currently have an ElasticSearch index with a mapping that I do not want to change (to expensive to reindex). Here from is used as a field name. Is there any way to assign a mapping to this field with elasticsearch-dsl?

class BlogPost(Document):
    from = Keyword()

The conventional way of having it as a class attribute fails because from is a Python keyword and not allowed in this place.

@craynic
Copy link

craynic commented Jul 7, 2020

It seems that you could use an attribute mapping in class Meta to define extra fields.
link

@lschmelzeisen
Copy link
Author

I'm not sure whether this does what I need it to do. Would you mind to provide some short example code?

@miguelgrinberg
Copy link
Collaborator

Also mentioned in #1659

@miguelgrinberg
Copy link
Collaborator

Closing this one, since it is a duplicate of #1659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants