Skip to content

Commit 5af6735

Browse files
committed
Percolate API fixes and mpercolate and count_percolate
1 parent ab4f386 commit 5af6735

File tree

1 file changed

+97
-12
lines changed

1 file changed

+97
-12
lines changed

elasticsearch/client/__init__.py

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,107 @@ def suggest(self, body, index=None, params=None):
597597
params=params, body=body)
598598
return data
599599

600-
@query_params('prefer_local')
601-
def percolate(self, index, doc_type, body, params=None):
600+
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
601+
'percolate_index', 'percolate_type', 'preference', 'routing', 'version',
602+
'version_type')
603+
def percolate(self, index, doc_type, id=None, body=None, params=None):
604+
"""
605+
The percolator allows to register queries against an index, and then
606+
send percolate requests which include a doc, and getting back the
607+
queries that match on that doc out of the set of registered queries.
608+
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html>`_
609+
610+
:arg index: The index of the document being percolated.
611+
:arg doc_type: The type of the document being percolated.
612+
:arg id: Substitute the document in the request body with a document
613+
that is known by the specified id. On top of the id, the index and
614+
type parameter will be used to retrieve the document from within the
615+
cluster.
616+
:arg body: The percolator request definition using the percolate DSL
617+
:arg allow_no_indices: Whether to ignore if a wildcard indices
618+
expression resolves into no concrete indices. (This includes `_all`
619+
string or when no indices have been specified)
620+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
621+
indices that are open, closed or both., default 'open'
622+
:arg ignore_unavailable: Whether specified concrete indices should be
623+
ignored when unavailable (missing or closed)
624+
:arg percolate_index: The index to percolate the document into. Defaults
625+
to index.
626+
:arg percolate_type: The type to percolate document into. Defaults to
627+
type.
628+
:arg preference: Specify the node or shard the operation should be
629+
performed on (default: random)
630+
:arg routing: A comma-separated list of specific routing values
631+
:arg version: Explicit version number for concurrency control
632+
:arg version_type: Specific version type
602633
"""
603-
Send a percolate request which include a doc, and get back the queries
604-
that match on that doc out of the set of registered queries.
634+
_, data = self.transport.perform_request('GET', _make_path(index,
635+
doc_type, id, '_percolate'), params=params, body=body)
636+
return data
637+
638+
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable')
639+
def mpercolate(self, body, index=None, doc_type=None, params=None):
640+
"""
641+
The percolator allows to register queries against an index, and then
642+
send percolate requests which include a doc, and getting back the
643+
queries that match on that doc out of the set of registered queries.
605644
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html>`_
606645
607-
:arg index: The name of the index with a registered percolator query
608-
:arg doc_type: The document type
609-
:arg body: The document (`doc`) to percolate against registered queries;
610-
optionally also a `query` to limit the percolation to specific registered queries
611-
:arg prefer_local: With `true`, specify that a local shard should be
612-
used if available, with `false`, use a random shard (default: true)
646+
:arg index: The index of the document being count percolated to use as
647+
default
648+
:arg doc_type: The type of the document being percolated to use as
649+
default.
650+
:arg body: The percolate request definitions (header & body pair),
651+
separated by newlines
652+
:arg allow_no_indices: Whether to ignore if a wildcard indices
653+
expression resolves into no concrete indices. (This includes `_all`
654+
string or when no indices have been specified)
655+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
656+
indices that are open, closed or both., default 'open'
657+
:arg ignore_unavailable: Whether specified concrete indices should be
658+
ignored when unavailable (missing or closed)
659+
"""
660+
_, data = self.transport.perform_request('GET', _make_path(index,
661+
doc_type, '_mpercolate'), params=params, body=self._bulk_body(body))
662+
return data
663+
664+
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
665+
'percolate_index', 'percolate_type', 'preference', 'routing', 'version',
666+
'version_type')
667+
def count_percolate(self, index, doc_type, id=None, body=None, params=None):
613668
"""
614-
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_percolate'),
615-
params=params, body=body)
669+
The percolator allows to register queries against an index, and then
670+
send percolate requests which include a doc, and getting back the
671+
queries that match on that doc out of the set of registered queries.
672+
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html>`_
673+
674+
:arg index: The index of the document being count percolated.
675+
:arg doc_type: The type of the document being count percolated.
676+
:arg id: Substitute the document in the request body with a document
677+
that is known by the specified id. On top of the id, the index and
678+
type parameter will be used to retrieve the document from within the
679+
cluster.
680+
:arg body: The count percolator request definition using the percolate
681+
DSL
682+
:arg allow_no_indices: Whether to ignore if a wildcard indices
683+
expression resolves into no concrete indices. (This includes `_all`
684+
string or when no indices have been specified)
685+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
686+
indices that are open, closed or both., default 'open'
687+
:arg ignore_unavailable: Whether specified concrete indices should be
688+
ignored when unavailable (missing or closed)
689+
:arg percolate_index: The index to count percolate the document into.
690+
Defaults to index.
691+
:arg percolate_type: The type to count percolate document into. Defaults
692+
to type.
693+
:arg preference: Specify the node or shard the operation should be
694+
performed on (default: random)
695+
:arg routing: A comma-separated list of specific routing values
696+
:arg version: Explicit version number for concurrency control
697+
:arg version_type: Specific version type
698+
"""
699+
_, data = self.transport.perform_request('GET', _make_path(index,
700+
doc_type, id, '_percolate', 'count'), params=params, body=body)
616701
return data
617702

618703
@query_params('boost_terms', 'max_doc_freq', 'max_query_terms',

0 commit comments

Comments
 (0)