pandagg.tree.mappings module

class pandagg.tree.mappings.Mappings(properties=None, dynamic=False, **kwargs)[source]

Bases: pandagg.tree._tree.Tree

list_nesteds_at_field(field_path)[source]

List nested paths that apply at a given path.

>>> mappings = Mappings(dynamic=False, properties={
>>>     'id': {'type': 'keyword'},
>>>     'comments': {'type': 'nested', 'properties': {
>>>         'comment_text': {'type': 'text'},
>>>         'date': {'type': 'date'}
>>>     }}
>>> })
>>> mappings.list_nesteds_at_field('id')
[]
>>> mappings.list_nesteds_at_field('comments')
['comments']
>>> mappings.list_nesteds_at_field('comments.comment_text')
['comments']
mapping_type_of_field(field_path)[source]

Return field type of provided field path.

>>> mappings = Mappings(dynamic=False, properties={
>>>     'id': {'type': 'keyword'},
>>>     'comments': {'type': 'nested', 'properties': {
>>>         'comment_text': {'type': 'text'},
>>>         'date': {'type': 'date'}
>>>     }}
>>> })
>>> mappings.mapping_type_of_field('id')
'keyword'
>>> mappings.mapping_type_of_field('comments')
'nested'
>>> mappings.mapping_type_of_field('comments.comment_text')
'text'
nested_at_field(field_path)[source]

Return nested path applied on a given path. Return None is none applies.

>>> mappings = Mappings(dynamic=False, properties={
>>>     'id': {'type': 'keyword'},
>>>     'comments': {'type': 'nested', 'properties': {
>>>         'comment_text': {'type': 'text'},
>>>         'date': {'type': 'date'}
>>>     }}
>>> })
>>> mappings.nested_at_field('id')
None
>>> mappings.nested_at_field('comments')
'comments'
>>> mappings.nested_at_field('comments.comment_text')
'comments'
node_class

alias of pandagg.node.mappings.abstract.Field

to_dict(from_=None, depth=None)[source]

Serialize Mappings as dict.

Parameters:from – identifier of a field, if provided, limits serialization to this field and its

children (used for recursion, shouldn’t be useful) :param depth: integer, if provided, limit the serialization to a given depth :return: dict

validate_agg_clause(agg_clause, exc=True)[source]

Ensure that if aggregation clause relates to a field (field or path) this field exists in mappings, and that required aggregation type is allowed on this kind of field.

Parameters:
  • agg_clause – AggClause you want to validate on these mappings
  • exc – boolean, if set to True raise exception if invalid
Return type:

boolean

validate_document(d)[source]