elastic / elasticsearch-dsl-py

High level Python client for Elasticsearch
http://elasticsearch-dsl.readthedocs.org
Apache License 2.0
3.8k stars 801 forks source link

Adding a refresh document method #1056

Open WisdomPill opened 5 years ago

WisdomPill commented 5 years ago

Hello! I have a document that gets updated by a different process/thread that might be in a different machine. I would like to add a helper method in DocType class to refresh the document like the classic django refresh_from_db.

Do you agree with my small proposal? I think the library would benefit from this kind of utility methods that make the library adapt more to the common glue code that need to be added by the majority of users.

Best regards, WisdomPill

honzakral commented 5 years ago

Hi, I do like the proposal but I am a bit worried about the namespace - with elasticsearch documents we don't have a fixed number of fields but instead work with dynamic documents where any field name can be added at any time. For this reason I explicitly kept the number of methods to a minimum.

Would you think that just documenting this (doc = doc.get(id=doc.meta.id)) would be an ok replacement for a method? If not, I would be open to a PR

Thank you!

WisdomPill commented 5 years ago

No, I think a refresh_from_es or refresh_doc would be cleaner, besides that why your suggestion does not have the index in the get method?

Maybe is better to use a name like the ones I just mentioned so we lower the chances to have a field with the same name, like django models do with refresh_from_db.

If you are okay with that I would definitely be open to do the PR

Best regards, Anas

P.S. Sorry I forgot about the issue