Skip to content

Commit

Permalink
Merge master into 'faster' to get new update_aliases().
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrose committed Dec 18, 2014
2 parents 8bdcc08 + 819281c commit 9ece872
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
23 changes: 23 additions & 0 deletions docs/source/changelog.rst
@@ -1,6 +1,29 @@
Changelog
=========

v0.7.1 (2014-08-12)
-------------------

* Brings tests up to date with ``update_aliases()`` API change.


v0.7 (2014-08-12)
-----------------

* When an ``id_field`` is specified for ``bulk_index()``, don't index it under
its original name as well; use it only as the ``_id``.
* Rename ``aliases()`` to ``get_aliases()`` for consistency with other
methods. Original name still works but is deprecated. Add an ``alias`` kwarg
to the method so you can fetch specific aliases.

.. warning::

Backward incompatible:

* ``update_aliases()`` no longer requires a dict with an ``actions`` key;
that much is implied. Just pass the value of that key.


v0.6.1 (2013-11-01)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion pyelasticsearch/__init__.py
Expand Up @@ -11,7 +11,7 @@
__all__ = ['ElasticSearch', 'ElasticHttpError', 'InvalidJsonResponseError',
'Timeout', 'ConnectionError', 'ElasticHttpNotFoundError',
'IndexAlreadyExistsError']
__version__ = '0.7'
__version__ = '0.7.1'
__version_info__ = tuple(__version__.split('.'))

get_version = lambda: __version_info__
33 changes: 22 additions & 11 deletions pyelasticsearch/client.py
Expand Up @@ -281,8 +281,9 @@ def _raise_exception(self, response, decoded_body):
error_class = ElasticHttpError
if response.status == 404:
error_class = ElasticHttpNotFoundError
elif (error_message.startswith('IndexAlreadyExistsException') or
'nested: IndexAlreadyExistsException' in error_message):
elif (hasattr(error_message, 'startswith') and
(error_message.startswith('IndexAlreadyExistsException') or
'nested: IndexAlreadyExistsException' in error_message)):
error_class = IndexAlreadyExistsError

raise error_class(response.status, error_message)
Expand Down Expand Up @@ -725,34 +726,44 @@ def status(self, index=None, query_params=None):
query_params=query_params)

@es_kwargs()
def update_aliases(self, settings, query_params=None):
def update_aliases(self, actions, query_params=None):
"""
Add, remove, or update aliases in bulk.
Atomically add, remove, or update aliases in bulk.
:arg settings: a dictionary specifying the actions to perform
:arg actions: A list of the actions to perform
See `ES's admin-indices-aliases API`_.
.. _`ES's admin-indices-aliases API`:
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html
"""
return self.send_request('POST', ['_aliases'],
body=settings, query_params=query_params)
body={'actions': actions},
query_params=query_params)

@es_kwargs()
def aliases(self, index=None, query_params=None):
@es_kwargs('ignore_unavailable')
def get_aliases(self, index=None, alias='*', query_params=None):
"""
Retrieve a listing of aliases
:arg index: the name of an index or an iterable of indices
:arg index: The name of an index or an iterable of indices from which
to fetch aliases. If omitted, look in all indices.
:arg alias: The name of the alias to return or an iterable of them.
Wildcard * is supported. If this arg is omitted, return all aliases.
See `ES's admin-indices-aliases API`_.
.. _`ES's admin-indices-aliases API`:
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html
"""
return self.send_request('GET', [self._concat(index), '_aliases'],
query_params=query_params)
return self.send_request(
'GET',
[self._concat(index), '_aliases', self._concat(alias)],
query_params=query_params)

def aliases(self, *args, **kwargs):
# Deprecated.
return self.get_aliases(*args, **kwargs)

@es_kwargs()
def create_index(self, index, settings=None, query_params=None):
Expand Down
26 changes: 7 additions & 19 deletions pyelasticsearch/tests/client_tests.py
Expand Up @@ -260,32 +260,20 @@ def test_update(self):

def test_alias_index(self):
self.conn.create_index('test-index')
settings = {
"actions": [
{"add": {"index": "test-index", "alias": "test-alias"}}
]
}
result = self.conn.update_aliases(settings)
actions = [{"add": {"index": "test-index", "alias": "test-alias"}}]
result = self.conn.update_aliases(actions)
self.assert_result_contains(result, {'acknowledged': True, 'ok': True})

def test_alias_nonexistent_index(self):
settings = {
"actions": [
{"add": {"index": "test1", "alias": "alias1"}}
]
}
actions = [{"add": {"index": "test1", "alias": "alias1"}}]
assert_raises(ElasticHttpNotFoundError,
self.conn.update_aliases,
settings)
self.conn.update_aliases,
actions)

def test_list_aliases(self):
self.conn.create_index('test-index')
settings = {
"actions": [
{"add": {"index": "test-index", "alias": "test-alias"}}
]
}
self.conn.update_aliases(settings)
actions = [{"add": {"index": "test-index", "alias": "test-alias"}}]
self.conn.update_aliases(actions)
result = self.conn.aliases('test-index')
eq_(result, {u'test-index': {u'aliases': {u'test-alias': {}}}})

Expand Down

0 comments on commit 9ece872

Please sign in to comment.