-
Notifications
You must be signed in to change notification settings - Fork 270
Configure Elasticsearch _id dynamically from document #272
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
Conversation
@@ -156,11 +156,19 @@ def parallel_bulk(self, actions, **kwargs): | |||
# the result is currently not used upstream anyway. | |||
return (1, []) | |||
|
|||
def document_id(self, object_instance): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the method name to get_document_id
. document_id
seems like a property
from developer point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get your point concerning the method name, but I have a feeling that get_document_id
may be misleading, as this is not really a getter. It's more like a setter. It is basically the same as the prepare_<field name>
methods, but for the document id instead of one of its fields.
I did not use the name prepare_document_id
or prepare_id
, as this would conflict with the methods that would set the document_id
or id
field inside the document.
Would you be ok with one of the following names?
set_id
set_document_id
determine_document_id
determine_id
Tell me which one you prefer and I'll do the changes.
And I'll add tests as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is not setter as it is not setting any atribute to the object itself. the method is returning the id so from independent prespective, it is a getter. You can change it to something like generate_id
, which maybe more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, it's not a setter either. Ok for generate_id
then.
@jfschaff Thanks a lot for the PR. I have added 2 improvements which I think are helpful. Let me know if you have concerns. |
@@ -156,11 +156,19 @@ def parallel_bulk(self, actions, **kwargs): | |||
# the result is currently not used upstream anyway. | |||
return (1, []) | |||
|
|||
def generate_id(self, object_instance): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to have static method so it can be called directly without initiating the object. Like Document.generate_id(model_object)
I will check the tests and add some more review. |
OK, then I wait for your review before I make the final fixes. |
@jfschaff The tests looks pretty good. Can you add a unittest in the |
@jfschaff I was thinking about adding a configuration in the It is not necessary to have this in this patch, we can implement that in separate PR. But are you interested to add that as well in this PR? |
Co-authored-by: Safwan Rahman <[email protected]>
Co-authored-by: Safwan Rahman <[email protected]>
Hi, and thank you for your feedback. I could not find a way to retrieve the ES Therefore, the integration tests use As for the other points:
And yes, your suggestion about adding |
Are we able to merge this in? |
@nicholasamorim @jfschaff Sorry I could not manage time to fix the tests. I will look on this upcoming weekend for sure. |
@jfschaff Thanks for your patience. I have fixed the tests in my repo safwanrahman@4c88715d can you fetch and cherry-pick the commit and push this to your branch? Or you may mark the "allow edit from maintainers" so I can push the changes directly to your repo. The test fix is quite interesting and complex. The method is not called untill the low level elasticsearch API execute it. So the tests was not picking up. |
@safwanrahman, I've just pushed your commit to my branch, but I don't see the tests running... |
Seems like the tests got passed! Going to merge this! Thanks a lot! |
Implements #271
CL:
document_id(self, instance)
toDocument
class to customize Elasticsearch document idsfields
I wasn't sure where to put the doc, so don't hesitate to move it around it you think it shouldn't be in this section.