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 passing any request parameter to the create index API #642

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion esrally/driver/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,12 @@ def __call__(self, es, params):
indices = mandatory(params, "indices", self)
request_params = params.get("request-params", {})
for index, body in indices:
es.indices.create(index=index, body=body, **request_params)
# We don't use es.indices.create() because it doesn't support params
# Ref: https://elasticsearch-py.readthedocs.io/en/master/api.html?highlight=indices%20create#elasticsearch.client.IndicesClient.create
es.transport.perform_request(method="PUT",
url="/{}".format(index),
body=body,
params=request_params)
return len(indices), "ops"

def __repr__(self, *args, **kwargs):
Expand Down
14 changes: 8 additions & 6 deletions tests/driver/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,23 +1275,25 @@ class CreateIndexRunnerTests(TestCase):
def test_creates_multiple_indices(self, es):
r = runner.CreateIndex()

request_params = {
"wait_for_active_shards": True
}

params = {
"indices": [
("indexA", {"settings": {}}),
("indexB", {"settings": {}}),
],
"request-params": {
"wait_for_active_shards": True
}
"request-params": request_params
}

result = r(es, params)

self.assertEqual((2, "ops"), result)

es.indices.create.assert_has_calls([
mock.call(index="indexA", body={"settings": {}}, wait_for_active_shards=True),
mock.call(index="indexB", body={"settings": {}}, wait_for_active_shards=True)
es.transport.perform_request.assert_has_calls([
mock.call(method="PUT", url="/indexA", body={"settings": {}}, params=request_params),
mock.call(method="PUT", url="/indexB", body={"settings": {}}, params=request_params)
])

@mock.patch("elasticsearch.Elasticsearch")
Expand Down