class_docstr: Group of functions related to elasticsearch aggregations requests
class_docstr_tok: ["Group","of","functions","related","to","elasticsearch","aggregations","requests"]
docstr: Build a set of aggregations for a given field definition (extracted from index mapping)
docstr_tok: ["Build","a","set","of","aggregations","for","a","given","field","definition","(","extracted","from","index","mapping",")"]
code: def custom_fields(
      fields_definitions: Dict[str, str],
      size: int = DEFAULT_AGGREGATION_SIZE,
  ) -> Dict[str, Dict[str, Any]]:
      """Build a set of aggregations for a given field definition (extracted from index mapping)"""
  
      def __resolve_aggregation_for_field_type(
          field_type: str, field_name: str
      ) -> Optional[Dict[str, Any]]:
          if field_type in ["keyword", "long", "integer", "boolean"]:
              return aggregations.terms_aggregation(
                  field_name=field_name, size=size
              )
          if field_type in ["float", "date"]:
              # TODO: Revise boxplot (since elasticsearch version 7.11 and not sure for opensearch)
              return {"extended_stats": {"field": field_name}}
          return None  # TODO: revise elasticsearch aggregations for API match
  
      if not fields_definitions:
          return {}
  
      return {
          key: aggregation
          for key, type_ in fields_definitions.items()
          for aggregation in [
              __resolve_aggregation_for_field_type(
                  type_, field_name=key
              )
          ]
          if aggregation
      }
  
imports: from enum import Enum
  from typing import Any, Dict, List, Optional, Type, Union
  from argilla.server.commons.models import TaskStatus
  from argilla.server.daos.backend.mappings.helpers import mappings
  from argilla.server.pydantic_v1 import BaseModel
label_desc: Use image node_id 5 for calling the aggregations obj's underlying member method code with example usage: obj.custom_fields(fields_definitions, size) and returns: unknown, None, dict, aggregations, dict