pandagg.tree.query.abstract module

class pandagg.tree.query.abstract.Compound(**kwargs)[source]

Bases: pandagg.tree.query.abstract.Query

KEY = None
class pandagg.tree.query.abstract.Leaf(*args, **kwargs)[source]

Bases: pandagg.tree.query.abstract.Query

KEY = None
class pandagg.tree.query.abstract.Query(*args, **kwargs)[source]

Bases: pandagg.tree._tree.Tree

Combination of query clauses.

Mapping declaration is optional, but doing so validates query validity and automatically inserts nested clauses when necessary.

Keyword Arguments:
 
  • mapping (dict or pandagg.tree.mapping.Mapping) – Mapping of requested indice(s). Providing it will add validation features, and add required nested clauses if missing.
  • nested_autocorrect (bool) – In case of missing nested clauses in query, if True, automatically add missing nested clauses, else raise error.
  • remaining kwargs: Used as body in query clauses.
KEY = None
applied_nested_path_at_node(nid)[source]
bool(*args, **kwargs)[source]
boost(*args, **kwargs)[source]
constant_score(*args, **kwargs)[source]
dis_max(*args, **kwargs)[source]
filter(*args, **kwargs)[source]
function_score(*args, **kwargs)[source]
has_child(*args, **kwargs)[source]
has_parent(*args, **kwargs)[source]
must(*args, **kwargs)[source]
must_not(*args, **kwargs)[source]
nested(*args, **kwargs)[source]
node_class

alias of pandagg.node.query.abstract.QueryClause

parent_id(*args, **kwargs)[source]
pinned_query(*args, **kwargs)[source]
query(*args, **kwargs)[source]

Insert new clause(s) in current query.

Inserted clause can accepts following syntaxes.

Given an empty query:

>>> from pandagg.query import Query
>>> q = Query()

flat syntax: clause type, followed by query clause body as keyword arguments:

>>> q.query('term', some_field=23)
{'term': {'some_field': 23}}

from regular Elasticsearch dict query:

>>> q.query({'term': {'some_field': 23}})
{'term': {'some_field': 23}}

using pandagg DSL:

>>> from pandagg.query import Term
>>> q.query(Term(field=23))
{'term': {'some_field': 23}}
Keyword Arguments:
 
  • parent (str) – named query clause under which the inserted clauses should be placed.
  • parent_param (str optional parameter when using parent param) – parameter under which inserted clauses will be placed. For instance if parent clause is a boolean, can be ‘must’, ‘filter’, ‘should’, ‘must_not’.
  • child (str) – named query clause above which the inserted clauses should be placed.
  • child_param (str optional parameter when using parent param) – parameter of inserted boolean clause under which child clauses will be placed. For instance if inserted clause is a boolean, can be ‘must’, ‘filter’, ‘should’, ‘must_not’.
  • mode (str one of ‘add’, ‘replace’, ‘replace_all’) – merging strategy when inserting clauses on a existing compound clause.
    • ‘add’ (default) : adds new clauses keeping initial ones
    • ‘replace’ : for each parameter (for instance in ‘bool’ case : ‘filter’, ‘must’, ‘must_not’, ‘should’), replace existing clauses under this parameter, by new ones only if declared in inserted compound query
    • ‘replace_all’ : existing compound clause is completely replaced by the new one
script_score(*args, **kwargs)[source]
should(*args, **kwargs)[source]
show(*args, **kwargs)[source]

Return tree structure in hierarchy style.

Parameters:
  • nid – Node identifier from which tree traversal will start. If None tree root will be used
  • filter_ – filter function performed on nodes. Nodes excluded from filter function nor their children won’t be displayed
  • reverse – the reverse param for sorting Node objects in the same level
  • key – key used to order nodes of same parent
  • reverse – reverse parameter applied at sorting
  • line_type – display type choice
  • limit – int, truncate tree display to this number of lines
  • kwargs – kwargs params passed to node line_repr method
Return type:

unicode in python2, str in python3

to_dict(from_=None, with_name=True)[source]

Serialize query as native dict. :param from_: optional, :param with_name: optional :return: