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

Allow routing of bulk API actions #631

Merged
merged 4 commits into from
Jun 12, 2014
Merged

Conversation

xyu
Copy link
Contributor

@xyu xyu commented Jun 11, 2014

The elasticsearch bulk API allows for each item to have a routing value. This is especially helpful for bulk delete calls, which when set helps prevent those actions from being broadcast to all shards needlessly.

This change adds a optional parameter to the deleteIds() method which when set will route all deletes for the given id with the given routing value.

I also thought about perhaps allowing the ids array to be an array of id / routing key pairs however that seemed needlessly complicated and users can simply call deleteIds() multiple times with grouping ids with the same routing value if needed. (For our use case when we are bulk deleting by ids we are bulk deleting a bunch of related documents which are routed to the same shard.)

xyu added 3 commits June 11, 2014 12:06
The elasticsearch bulk API allows for each item to have a routing value
which helps prevent bulk actions from being broadcast to all shards.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-routing
If all ids to be deleted during a bulk API request are routed to the same
shard allow that routing value to be set so that the delete command is not
broadcast to all shards.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling e86afac on xyu:route-bulk-actions into c622ccf on ruflin:master.

@@ -527,6 +528,9 @@ public function deleteIds(array $ids, $index, $type)
$action = new Action(Action::OP_TYPE_DELETE);
$action->setId($id);

if (!empty($routing))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use { } also if it only one line inside the if clause?

@ruflin
Copy link
Owner

ruflin commented Jun 11, 2014

Thx for the addition. For the test changes, I would suggest to add new additional tests instead of changing the existing tests (if not needed). So we can make sure, the old behaviour still exists, but a new one was added. Also instead of having large tests, we can have very small unit tests that only test one thing (if possible).

ruflin added a commit that referenced this pull request Jun 12, 2014
Allow routing of bulk API actions
@ruflin ruflin merged commit 2e2096f into ruflin:master Jun 12, 2014
@xyu
Copy link
Contributor Author

xyu commented Jun 12, 2014

Thanks @ruflin!

I didn't get a chance to cleanup the tests like you suggested yesterday, let me know if you still want new tests for this change as opposed to the changed tests.

@ruflin
Copy link
Owner

ruflin commented Jun 13, 2014

@xyu Yes, it would be very nice if you could also update the tests and make an new pull request. I merged it yesterday as other pull requests came in an I wanted to make sure not to have any conflicts.

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.

3 participants