pandagg.tree.mappings module¶
-
class
pandagg.tree.mappings.
Mappings
(properties: Optional[Dict[str, Union[Dict[str, Any], pandagg.node.mappings.abstract.Field]]] = None, dynamic: Optional[bool] = None, **body)[source]¶ Bases:
pandagg.tree._tree.TreeReprMixin
,lighttree.tree.Tree
-
list_nesteds_at_field
(field_path: str) → List[str][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: str) → str[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: str) → Optional[str][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'
-
to_dict
(from_: Optional[str] = None, depth: Optional[int] = None) → pandagg.types.MappingsDict[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: pandagg.node.aggs.abstract.AggClause, exc: bool = True) → bool[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
-