diff --git a/README.md b/README.md index f930c97..e586d93 100644 --- a/README.md +++ b/README.md @@ -395,27 +395,27 @@ Creating a search key that will only search over the body field. ### Create a Meta Engine ```python ->>> client.create_engine('my-meta-engine', options={ - 'type': 'meta', - 'source_engines': [ - 'source-engine-1', - 'source-engine-2' - ] -}) +>>> client.create_meta_engine( + engine_name=engine_name, + source_engines=[ + 'source-engine-1', + 'source-engine-2' + ] +) {'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'} ``` ### Add a Source Engine to a Meta Engine ```python ->>> client.add_source_engines('my-meta-engine', ['source-engine-3']) +>>> client.add_meta_engine_sources('my-meta-engine', ['source-engine-3']) {'source_engines': ['source-engine-1', 'source-engine-2', 'source-engine-3'], 'type': 'meta', 'name': 'my-meta-engine'} ``` ### Remove a Source Engine from a Meta Engine ```python ->>> client.remove_source_engines('my-meta-engine', ['source-engine-3']) +>>> client.delete_meta_engine_sources('my-meta-engine', ['source-engine-3']) {'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'} ``` diff --git a/elastic_app_search/client.py b/elastic_app_search/client.py index 2b8f8e4..88919e7 100644 --- a/elastic_app_search/client.py +++ b/elastic_app_search/client.py @@ -292,11 +292,19 @@ def click(self, engine_name, options): endpoint = "engines/{}/click".format(engine_name) return self.session.request_ignore_response('post', endpoint, json=options) - def add_source_engines(self, engine_name, source_engines): + def create_meta_engine(self, engine_name, source_engines): + data = { + 'name': engine_name, + 'source_engines': source_engines, + 'type': 'meta' + } + return self.session.request('post', 'engines', json=data) + + def add_meta_engine_sources(self, engine_name, source_engines): endpoint = "engines/{}/source_engines".format(engine_name) return self.session.request('post', endpoint, json=source_engines) - def remove_source_engines(self, engine_name, source_engines): + def delete_meta_engine_sources(self, engine_name, source_engines): endpoint = "engines/{}/source_engines".format(engine_name) return self.session.request('delete', endpoint, json=source_engines) diff --git a/tests/test_client.py b/tests/test_client.py index 336667c..2a5f844 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -510,7 +510,19 @@ def test_click(self): self.client.click(self.engine_name, { 'query': 'cat', 'document_id': 'INscMGmhmX4'}) - def test_add_source_engines(self): + def test_create_meta_engine(self): + source_engines = ['source-engine-1', 'source-engine-2'] + expected_return = {'source_engines': source_engines, + 'type': 'meta', 'name': self.engine_name} + + with requests_mock.Mocker() as m: + url = "{}/{}".format(self.client.session.base_url, 'engines') + m.register_uri('POST', url, json=expected_return, status_code=200) + response = self.client.create_meta_engine( + self.engine_name, source_engines) + self.assertEqual(response, expected_return) + + def test_add_meta_engine_sources(self): target_source_engine_name = 'source-engine-3' expected_return = {'source_engines': [ 'source-engine-1', 'source-engine-2', target_source_engine_name], 'type': 'meta', 'name': self.engine_name} @@ -521,11 +533,11 @@ def test_add_source_engines(self): "engines/{}/source_engines".format(self.engine_name) ) m.register_uri('POST', url, json=expected_return, status_code=200) - response = self.client.add_source_engines( + response = self.client.add_meta_engine_sources( self.engine_name, [target_source_engine_name]) self.assertEqual(response, expected_return) - def test_remove_source_engines(self): + def test_delete_meta_engine_sources(self): source_engine_name = 'source-engine-3' expected_return = {'source_engines': [ 'source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': self.engine_name} @@ -537,6 +549,6 @@ def test_remove_source_engines(self): ) m.register_uri('DELETE', url, json=expected_return, status_code=200) - response = self.client.remove_source_engines( + response = self.client.delete_meta_engine_sources( self.engine_name, [source_engine_name]) self.assertEqual(response, expected_return)