Skip to content

Implementing hook for dynamically adding fields to mapping #1000

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
wants to merge 1 commit into from

Conversation

safwanrahman
Copy link
Contributor

For having the mapping dynamically generated, we need to have a hook that will get the fields dynamically. I believe, its needed by django-elasticsearch-dsl to generete Elasticsearch DSL mapping dynamically from Django model.
@honzakral As you have mentioned in your comment #930 (comment), is it a correct approach to have a hook for django-elasticsearch-dsl? I am currently trying to upgrade it for elasticsearch-dsl-py>6.1.0

@safwanrahman
Copy link
Contributor Author

Seems like it will not work! 😞

@safwanrahman
Copy link
Contributor Author

@honzakral Do you have any idea how to accomplish the feature to have a hook to dynamically generate the mapping?

@honzakral
Copy link
Contributor

There should be no need for an extra hook to add fields, you can always access the Mapping by doing DocClass._doc_type.mapping or DocClass._index._mapping and then you can easily call the .field() method there to add additional fields.

The only issue now is that if you add a field to the DocClass._doc_type.mapping it will not propagate up to the Index at DocClass._index (unless you create a new one) so DocClass.init() won't take it into account... I fixed that in ceac532

Hope this helps!

@honzakral honzakral closed this Aug 26, 2018
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

Successfully merging this pull request may close these issues.

2 participants