Skip to content

Commit

Permalink
Fix spuriously failing percolator test. Bring percolator es_kwargs up…
Browse files Browse the repository at this point in the history
… to date.

Get willkg's test fixes into the changelog as well.
  • Loading branch information
erikrose committed Jan 23, 2015
1 parent 55e2bf9 commit b1a605f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/source/changelog.rst
Expand Up @@ -8,6 +8,9 @@ v0.8.0
much of which was borrowed from us anyway.
* Make bulk indexing (and likely other network things) 15 times faster.
* Fix ``delete_by_query()`` to work with ES 1.0 and later.
* Bring ``percolate()`` es_kwargs up to date.
* Fix all tests that were failing on modern versions of ES.
* Tolerate errors that are non-strings and create exceptions for them properly.

.. note::

Expand Down
6 changes: 4 additions & 2 deletions pyelasticsearch/client.py
Expand Up @@ -946,7 +946,8 @@ def cluster_state(self, metric='_all', index='_all', query_params=None):
['_cluster', 'state', self._concat(metric), self._concat(index)],
query_params=query_params)

@es_kwargs()
@es_kwargs('routing', 'preference', 'ignore_unavailable',
'percolate_format')
def percolate(self, index, doc_type, doc, query_params=None):
"""
Run a JSON document through the registered percolator queries, and
Expand All @@ -966,7 +967,8 @@ def percolate(self, index, doc_type, doc, query_params=None):
"""
return self.send_request('GET',
[index, doc_type, '_percolate'],
doc, query_params=query_params)
doc,
query_params=query_params)


class JsonEncoder(json.JSONEncoder):
Expand Down
14 changes: 7 additions & 7 deletions pyelasticsearch/tests/client_tests.py
Expand Up @@ -299,27 +299,27 @@ def test_percolate(self):

# Index a few queries in the percolator
result = self.conn.index(
'_percolator',
'test-index',
'.percolator',
{'query': {'match': {'name': 'Joe'}}},
id='id_1')
result = self.conn.index(
'_percolator',
'test-index',
'.percolator',
{'query': {'match': {'name': 'not_that_guy'}}},
id='id_2')

# Percolate a document that should match query ID 1:
document = {'doc': {'name': 'Joe'}}
result = self.conn.percolate('test-index','test-type', document)
self.assert_result_contains(result, {'matches': ['id_1'], 'ok': True})
result = self.conn.percolate('test-index', 'test-type', document)
self.assert_result_contains(
result,
{'matches': [{'_id': 'id_1', '_index': 'test-index'}]})

# Percolate a document that shouldn't match any queries
document = { 'doc': {'name': 'blah'} }
result = self.conn.percolate('test-index', 'test-type', document)
self.assert_result_contains(result, {'matches': [], 'ok': True})

self.conn.delete_index('_percolator')
self.assert_result_contains(result, {'matches': []})


class SearchTestCase(ElasticSearchTestCase):
Expand Down

0 comments on commit b1a605f

Please sign in to comment.