diff --git a/elasticsearch/client.py b/elasticsearch/client.py index 1d9b9cd6..cd0d966c 100644 --- a/elasticsearch/client.py +++ b/elasticsearch/client.py @@ -76,7 +76,40 @@ class ClusterClient(NamespacedClient): pass class InidicesClient(NamespacedClient): - pass + @query_params('timeout') + def create(self, index, body=None, params=None): + """ + Create index in Elasticsearch. + http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/ + + :arg index: The name of the index + :arg timeout: Explicit operation timeout + """ + status, data = self.transport.perform_request('PUT', '/%s' % quote_plus(index), params=params, body=body) + return data + + @query_params('timeout') + def delete(self, index=None, params=None): + """ + Delete index in Elasticsearch + http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/ + + :arg timeout: Explicit operation timeout + """ + url = '/' if not index else '/' + _normalize_list(index) + status, data = self.transport.perform_request('DELETE', url, params=params) + return data + + @query_params() + def exists(self, index, params=None): + """ + http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/ + + :arg index: A comma-separated list of indices to check + """ + status, data = self.transport.perform_request('HEAD', '/' + _normalize_list(index), params=params) + return data + class Elasticsearch(object): """ diff --git a/test_elasticsearch/test_client/test_indices.py b/test_elasticsearch/test_client/test_indices.py new file mode 100644 index 00000000..7ba63d93 --- /dev/null +++ b/test_elasticsearch/test_client/test_indices.py @@ -0,0 +1,14 @@ +from test_elasticsearch.test_cases import ElasticsearchTestCase + +class TestIndices(ElasticsearchTestCase): + def test_create_one_index(self): + self.client.indices.create('test-index') + self.assert_url_called('PUT', '/test-index') + + def test_delete_multiple_indices(self): + self.client.indices.delete(['test-index', 'second.index', 'third/index']) + self.assert_url_called('DELETE', '/test-index%2Csecond.index%2Cthird%2Findex') + + def test_exists_index(self): + self.client.indices.exists('second.index,third/index') + self.assert_url_called('HEAD', '/second.index%2Cthird%2Findex')