class_docstr: Group of functions related to elasticsearch aggregations requests
class_docstr_tok: ["Group","of","functions","related","to","elasticsearch","aggregations","requests"]
code: def terms_aggregation(
      field_name: str = None,
      script: Union[str, Dict[str, Any]] = None,
      missing: Optional[str] = None,
      size: int = DEFAULT_AGGREGATION_SIZE,
  ):
      assert (
          field_name or script
      ), "Either field name or script must be provided"
      if script:
          query_part = {"script": script}
      else:
          query_part = {"field": field_name}
  
      dynamic_args = {}
      if missing is not None:
          dynamic_args["missing"] = missing
  
      return {
          "meta": {"kind": "terms"},
          "terms": {
              **query_part,
              "size": min(
                  size or aggregations.DEFAULT_AGGREGATION_SIZE,
                  aggregations.MAX_AGGREGATION_SIZE,
              ),
              "order": {"_count": "desc"},
              **dynamic_args,
          },
      }
  
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 3 for calling the aggregations obj's underlying member method code with example usage: obj.terms_aggregation(field_name, script, missing, size) and returns: dict